# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
599929 | M_W | Amusement Park (CEOI19_amusementpark) | C++17 | 1 ms | 212 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |