# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
779320 | nonono | Amusement Park (CEOI19_amusementpark) | C++14 | 1 ms | 340 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>
#define int long long
using namespace std;
const int mod = 998244353;
const int N = 18;
int n, m;
int slide[N][N];
int Use[N][N];
long long dp1[1 << N], dp2[1 << N];
signed main(){
#define taskname ""
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i = 1; i <= m; i ++){
int a, b;
cin >> a >> b;
a -- ; b -- ;
slide[a][b] = 0;
slide[b][a] = 1;
Use[a][b] = 1;
Use[b][a] = 1;
}
for(int i = 0; i < n; i ++) dp1[1 << i] = 1;
for(int mask = 1; mask < (1 << n); mask ++){
for(int x = (1 << n) - 1 - mask; x > 0; x ^= x & (- x)){
int i = __builtin_ctz(x & (- x));
bool check = false;
for(int y = mask; y > 0; y ^= y & (- y)){
int j = __builtin_ctz(y & (- y));
check = (check || Use[j][i]);
}
if(check){
for(int y = mask; y > 0; y ^= y & (- y)){
int j = __builtin_ctz(y & (- y));
(dp2[mask ^ (1 << i)] += dp1[mask] * slide[j][i]) %= mod;
}
(dp2[mask ^ (1 << i)] += dp2[mask]) %= mod;
(dp1[mask ^ (1 << i)] += dp1[mask]) %= mod;
}
}
}
cout << dp2[(1 << n) - 1] << "\n";
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... |