Submission #1109352
Source Code Expand
#include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <vector> #define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i)) #define rep(i,n) FOR(i,0,n) #define pb push_back #define all(v) begin(v), end(v) #define debug(x) cerr<< #x <<": "<<x<<endl #define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vector<int> > vvi; typedef vector<ll> vll; typedef vector<vector<ll> > vvll; template<class T> using vv=vector<vector< T > >; int n, m; vvi g; vll dp; deque<bool> calculated; ll solve(int index) { if (calculated[index]) { return dp[index]; } set<int> s; rep (i, n) { if (((index >> i) & 1) == 1) { s.insert(i); } } for (int i : s) { bool continue_flag = false; for (int j : s) { if (i == j) { continue; } if (g[i][j] == 1) { continue_flag = true; break; } } if (continue_flag) { continue; } dp[index] += solve(index - (1 << i)); } calculated[index] = true; return dp[index]; } int main() { scanf("%d %d", &n, &m); g.assign(n, vi(n, 0)); rep (i, m) { int x, y; scanf("%d %d", &x, &y); x -= 1; y -= 1; g[x][y] = 1; } dp.assign((1 << n), 0); calculated.assign((1 << n), false); rep (i, n) { int index = (1 << i); dp[index] = 1; calculated[index] = true; } ll ans = solve((1 << n) - 1); printf("%lld\n", ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 徒競走 |
User | tspcx |
Language | C++14 (Clang 3.8.0) |
Score | 100 |
Code Size | 1917 Byte |
Status | AC |
Exec Time | 34 ms |
Memory | 896 KB |
Judge Result
Set Name | Sample | Subtask1 | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 30 / 30 | 70 / 70 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt |
Subtask1 | 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 | 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 3 ms | 256 KB |
0_01.txt | AC | 3 ms | 256 KB |
0_02.txt | AC | 34 ms | 896 KB |
1_00.txt | AC | 3 ms | 256 KB |
1_01.txt | AC | 3 ms | 256 KB |
1_02.txt | AC | 3 ms | 256 KB |
1_03.txt | AC | 3 ms | 256 KB |
1_04.txt | AC | 3 ms | 256 KB |
1_05.txt | AC | 3 ms | 256 KB |
1_06.txt | AC | 3 ms | 256 KB |
1_07.txt | AC | 3 ms | 256 KB |
1_08.txt | AC | 3 ms | 256 KB |
1_09.txt | AC | 3 ms | 256 KB |
1_10.txt | AC | 3 ms | 256 KB |
1_11.txt | AC | 3 ms | 256 KB |
1_12.txt | AC | 3 ms | 256 KB |
2_00.txt | AC | 34 ms | 896 KB |
2_01.txt | AC | 3 ms | 896 KB |
2_02.txt | AC | 3 ms | 896 KB |
2_03.txt | AC | 3 ms | 896 KB |
2_04.txt | AC | 3 ms | 512 KB |
2_05.txt | AC | 3 ms | 512 KB |
2_06.txt | AC | 3 ms | 512 KB |
2_07.txt | AC | 3 ms | 512 KB |
2_08.txt | AC | 4 ms | 896 KB |
2_09.txt | AC | 3 ms | 896 KB |
2_10.txt | AC | 3 ms | 896 KB |
2_11.txt | AC | 4 ms | 896 KB |
2_12.txt | AC | 6 ms | 896 KB |
2_13.txt | AC | 4 ms | 896 KB |
2_14.txt | AC | 5 ms | 896 KB |
2_15.txt | AC | 9 ms | 896 KB |