# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
599929 | 2022-07-20T09:37:13 Z | M_W | Amusement Park (CEOI19_amusementpark) | C++17 | 1 ms | 212 KB |
#include <bits/stdc++.h> using namespace std; int dp[210002][257]; // subset, cost vector<int> adj[19], rev[19]; vector<int> ss[19]; int main(){ int N, M; scanf("%d %d", &N, &M); for(int i = 0, u, v; i < M; i++){ scanf("%d %d", &u, &v); adj[u].push_back(v); rev[v].push_back(u); } for(int i = 0; i < 1 << N; i++){ int cnt = 0; for(int j = 0; j < N; j++){ if(i & 1 << j) cnt++; } ss[cnt].push_back(i); } for(int i = 0; i < N; i++) dp[1 << i][0] = 1; for(int i = 1; i <= N; i++){ // subset for(auto x : ss[i]){ // for(int i = 0; i <= M; i++){ // printf(">> %d %d: %d\n", x, i, dp[x][i]); // } for(int bit = 0; bit < N; bit++){ if(!(x & 1 << bit)){ int c = 0; for(auto u : adj[bit + 1]){ if(x & (1 << (u - 1))) c++; } for(int i = 0; i <= M; i++){ dp[x | (1 << bit)][i + c] += dp[x][i]; } } } } } long long ans = 0, md = 998244353; for(int i = 0; i <= M; i++){ ans = (ans + ((i * dp[(1 << N) - 1][i]) % md)) % md; } printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |