Submission #1175807


Source Code Expand

#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// bitDP
	int N, M; cin >> N >> M;
	vector<vector<int>>G(N, vector<int>(N, 0));
	rep(i, 0, M) {
		int x, y; cin >> x >> y; x--, y--;
		G[x][y] = 1;
	}
	vector<int>dp(1 << N, 0);
	dp[0] = 1;
	rep(bits, 1, 1 << N) {

		rep(j, 0, N) {
			if ((bits & 1 << j)) {
				bool f(true);
				rep(k, 0, N) {
					if (G[j][k] && bits & 1 << k)f = false;
				}
				if (f)dp[bits] += dp[bits ^ (1 << j)];
			}
		}
	}

	cout << dp[(1 << N) - 1] << endl;







	// メモ化再帰

	//int N, M; cin >> N >> M;
	//vector<vector<int>>G(N, vector<int>(N, 0));
	//vector<int>indeg(N, 0);
	//rep(i, 0, M) {
	//	int x, y; cin >> x >> y; x--, y--;
	//	G[x][y] = 1;
	//	indeg[y]++;
	//}
	//vector<long long>dp((1 << N), 0);

	//function<long long(int, vector<int>)>dfs = [&](int s, vector<int> v) -> long long {
	//	if (s == 0)return 1;

	//	if (dp[s] != 0)return dp[s];

	//	long long ans(0);
	//	rep(i, 0, N) {
	//		if (v[i] == 0 && s&(1 << i)) {
	//			vector<int>w(v);
	//			rep(j, 0, N)if (G[i][j])w[j]--;
	//			ans += dfs(s ^ (1 << i), w);
	//		}
	//	}
	//	return dp[s] = ans;
	//};

	//cout << dfs((1 << N) - 1, indeg) << endl;



	return 0;
}

Submission Info

Submission Time
Task D - 徒競走
User norma
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1843 Byte
Status AC
Exec Time 17 ms
Memory 768 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 30 / 30 70 / 70
Status
AC × 3
AC × 15
AC × 32
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 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 16 ms 768 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 1 ms 256 KB
1_02.txt AC 1 ms 256 KB
1_03.txt AC 1 ms 256 KB
1_04.txt AC 1 ms 256 KB
1_05.txt AC 1 ms 256 KB
1_06.txt AC 1 ms 256 KB
1_07.txt AC 1 ms 256 KB
1_08.txt AC 1 ms 256 KB
1_09.txt AC 1 ms 256 KB
1_10.txt AC 1 ms 256 KB
1_11.txt AC 1 ms 256 KB
1_12.txt AC 1 ms 256 KB
2_00.txt AC 16 ms 768 KB
2_01.txt AC 16 ms 768 KB
2_02.txt AC 16 ms 768 KB
2_03.txt AC 15 ms 768 KB
2_04.txt AC 8 ms 512 KB
2_05.txt AC 7 ms 512 KB
2_06.txt AC 8 ms 512 KB
2_07.txt AC 7 ms 512 KB
2_08.txt AC 16 ms 768 KB
2_09.txt AC 15 ms 768 KB
2_10.txt AC 15 ms 768 KB
2_11.txt AC 14 ms 768 KB
2_12.txt AC 16 ms 768 KB
2_13.txt AC 16 ms 768 KB
2_14.txt AC 17 ms 768 KB
2_15.txt AC 16 ms 768 KB