Submission #208161

#TimeUsernameProblemLanguageResultExecution timeMemory
208161E869120Amusement Park (CEOI19_amusementpark)C++14
100 / 100
2606 ms266744 KiB
#include <iostream> #include <algorithm> #include <vector> using namespace std; #pragma warning (disable: 4996) int mod = 998244353; int N, M, A[1009], B[1009]; int dp[387420489], power3[19], col[19]; vector<int> X[1009]; int main() { cin >> N >> M; for (int i = 1; i <= M; i++) { cin >> A[i] >> B[i]; A[i]--; B[i]--; } for (int i = 1; i <= M; i++) { X[A[i]].push_back(B[i]); X[B[i]].push_back(A[i]); } power3[0] = 1; for (int i = 1; i <= N; i++) power3[i] = 3LL * power3[i - 1]; for (int i = 0; i < N; i++) { int ret = 2 * power3[i]; for (int j = i + 1; j < N; j++) ret += power3[j]; for (int j : X[i]) { if (j < i) ret += power3[j]; } dp[ret] = 1; } for (int i = 0; i < power3[N]; i++) { if (dp[i] == 0) continue; int val = 0; for (int j = 0; j < N; j++) col[j] = (i / power3[j]) % 3; for (int j = 0; j < N; j++) { if (col[j] != 1) continue; int ret = i + power3[j] - val; for (int k : X[j]) { if ((col[k] == 1 && k < j) || col[k] == 0) ret += power3[k]; } dp[ret] += dp[i]; val += power3[j]; if (dp[ret] >= mod) dp[ret] -= mod; } } long long val = dp[power3[N] - 1]; val *= M; val %= mod; if (val % 2 == 1) val += mod; val /= 2LL; cout << val << endl; return 0; }

Compilation message (stderr)

amusementpark.cpp:5:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
amusementpark.cpp: In function 'int main()':
amusementpark.cpp:42:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if (val % 2 == 1) val += mod; val /= 2LL;
  ^~
amusementpark.cpp:42:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if (val % 2 == 1) val += mod; val /= 2LL;
                                ^~~
#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...