AtCoder Beginner Contest 041

Submission #788045

Source codeソースコード

#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;
int g[55][55];
int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  
  int n,m;
  cin>>n>>m;
  int x,y;
  rep(i,m){
    cin>>x>>y; --x; --y;
    g[x][y]=1;
  }
  vector<ll> dp(1<<n);
  dp[0]=1;
  rep(i,1<<n){
    rep(j,n){
      if(i>>j&1) continue;
      int f=1;
      rep(k,n)if((i>>k&1) && g[j][k]) f=0;
      if(f) dp[i|(1<<j)]+=dp[i];
    }
  }
  //cout<<dp;
  cout<<dp[(1<<n)-1]<<endl;
  return 0;
}

Submission

Task問題 D - 徒競走
User nameユーザ名 031_nuip
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1926 Byte
File nameファイル名
Exec time実行時間 46 ms
Memory usageメモリ使用量 768 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_00.txt,0_01.txt,0_02.txt
Subtask1 30 / 30 0_00.txt,0_01.txt,1_00.txt,1_01.txt,1_02.txt,1_03.txt,1_04.txt,1_05.txt,1_06.txt,1_07.txt,1_08.txt,1_09.txt,1_10.txt,1_11.txt,1_12.txt
All 70 / 70 0_00.txt,0_01.txt,0_02.txt,1_00.txt,1_01.txt,1_02.txt,1_03.txt,1_04.txt,1_05.txt,1_06.txt,1_07.txt,1_08.txt,1_09.txt,1_10.txt,1_11.txt,1_12.txt,2_00.txt,2_01.txt,2_02.txt,2_03.txt,2_04.txt,2_05.txt,2_06.txt,2_07.txt,2_08.txt,2_09.txt,2_10.txt,2_11.txt,2_12.txt,2_13.txt,2_14.txt,2_15.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_00.txt AC 4 ms 256 KB
0_01.txt AC 4 ms 256 KB
0_02.txt AC 44 ms 768 KB
1_00.txt AC 4 ms 256 KB
1_01.txt AC 4 ms 256 KB
1_02.txt AC 4 ms 256 KB
1_03.txt AC 4 ms 256 KB
1_04.txt AC 4 ms 256 KB
1_05.txt AC 4 ms 256 KB
1_06.txt AC 4 ms 256 KB
1_07.txt AC 6 ms 256 KB
1_08.txt AC 4 ms 256 KB
1_09.txt AC 4 ms 256 KB
1_10.txt AC 6 ms 256 KB
1_11.txt AC 4 ms 256 KB
1_12.txt AC 4 ms 256 KB
2_00.txt AC 44 ms 768 KB
2_01.txt AC 44 ms 768 KB
2_02.txt AC 44 ms 768 KB
2_03.txt AC 45 ms 768 KB
2_04.txt AC 23 ms 512 KB
2_05.txt AC 23 ms 512 KB
2_06.txt AC 23 ms 512 KB
2_07.txt AC 22 ms 512 KB
2_08.txt AC 45 ms 768 KB
2_09.txt AC 46 ms 768 KB
2_10.txt AC 45 ms 768 KB
2_11.txt AC 45 ms 768 KB
2_12.txt AC 45 ms 768 KB
2_13.txt AC 45 ms 768 KB
2_14.txt AC 45 ms 768 KB
2_15.txt AC 44 ms 768 KB