# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
806876 | 2023-08-04T10:43:15 Z | PanosPask | Amusement Park (CEOI19_amusementpark) | C++14 | 1 ms | 304 KB |
#include <bits/stdc++.h> #define mp make_pair #define f first #define s second #define pb push_back #define CHECK_BIT(val, pos) (val & (1 << pos)) using namespace std; const int MOD = (int)1e9 + 7; typedef long long ll; typedef pair<int, int> pi; int N, M; vector<vector<int>> adj_list; // dp[s]: Total cost and total number of ways vector<pi> dp; void add(int& a, int b) { a += b; if (a > MOD) a -= MOD; } void add(pi& a, pi b) { add(a.f, b.f); add(a.s, b.s); } int main(void) { scanf("%d %d", &N, &M); adj_list.resize(N); for (int i = 0; i < M; i++) { int u, v; scanf("%d %d", &u, &v); u--; v--; adj_list[u].pb(v); } dp.resize(1 << N); dp[0] = mp(0, 1); for (int i = 0; i < 1 << N; i++) { for (int u = 0; u < N; u++) { if (CHECK_BIT(i, u)) continue; int res = dp[i].f; int times = dp[i].s; for (auto v : adj_list[u]) { if (CHECK_BIT(i, v)) { add(res, times); } } add(dp[i ^ (1 << u)], mp(res, times)); } } printf("%d\n", dp[(1 << N) - 1].f); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 304 KB | Output is correct |
3 | Incorrect | 1 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |