# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208161 | E869120 | Amusement Park (CEOI19_amusementpark) | C++14 | 2606 ms | 266744 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 <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)
# | 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... |