Submission #806882

#TimeUsernameProblemLanguageResultExecution timeMemory
806882PanosPaskAmusement Park (CEOI19_amusementpark)C++14
0 / 100
1 ms212 KiB
#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 = 998244353; 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 (stderr)

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%d %d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~
amusementpark.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         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...