Submission #599937

#TimeUsernameProblemLanguageResultExecution timeMemory
599937M_WAmusement Park (CEOI19_amusementpark)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; int dp[210002][257]; // subset, cost vector<int> adj[19], rev[19]; vector<int> ss[19]; bool adjm[19][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); adjm[u][v] = adjm[v][u] = true; } 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; bool ok = false; for(auto u : rev[bit + 1]) if(x & (1 << (u - 1))) ok = true; for(auto u : adj[bit + 1]){ if(x & (1 << (u - 1))){ c++; ok = true; } } if(ok){ 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)

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~
amusementpark.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...