QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#491859 | #6555. Sets May Be Good | pandapythoner | WA | 0ms | 3720kb | C++23 | 2.5kb | 2024-07-25 23:47:06 | 2024-07-25 23:47:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, n) for(int i = 0; i < n; i += 1)
const ll inf = 1e18;
mt19937 rnd(234);
const ll mod = 998244353;
const int maxn = 1000;
int n, m;
char g[maxn][maxn];
char self_loop[maxn];
void swap_vertices(int u, int v) {
if (u == v) {
return;
}
swap(self_loop[u], self_loop[v]);
rep(i, n) {
swap(g[i][u], g[i][v]);
}
rep(i, n) {
swap(g[u][i], g[v][i]);
}
}
void make_flex(int u, int v) {
assert(u != v);
if (self_loop[u] and g[v][u]) {
} else if (self_loop[u]) {
self_loop[v] ^= 1;
g[u][v] ^= 1;
g[v][u] ^= 1;
} else if (g[u][v]) {
self_loop[v] ^= 1;
}
rep(i, n) if (i != u and i != v) g[i][v] = g[v][i] = (g[i][u] ^ g[i][v]);
}
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
cin >> n >> m;
rep(i, n) rep(j, n) g[i][j] = 0;
rep(i, n) self_loop[i] = 0;
for (int i = 0; i < m; i += 1) {
int u, v;
cin >> u >> v;
--u;
--v;
g[u][v] = g[v][u] = 1;
}
for (int i = 0; i < n - 1; i += 1) {
int to = -1;
for (int j = i + 1; j < n; j += 1) {
if (g[i][j]) {
to = j;
break;
}
}
if (to == -1) {
continue;
}
for (int j = to + 1; j < n; j += 1) {
if (g[i][j]) {
make_flex(to, j);
assert(g[i][j] == 0);
}
}
swap_vertices(to, i + 1);
}
array<array<ll, 2>, 2> dp;
rep(i, 2) rep(j, 2) dp[i][j] = 0;
dp[0][0] = 1;
for (int i = 0; i < n; i += 1) {
int d = 0;
if (i > 0) {
d = g[i][i - 1];
}
array<array<ll, 2>, 2> ndp;
rep(x, 2) rep(y, 2) ndp[x][y] = 0;
rep(prev, 2) rep(prev_sum, 2) rep(cur, 2) {
auto& new_val = ndp[(prev_sum + cur * self_loop[i] + d * cur * prev) % 2][cur];
new_val += dp[prev_sum][prev];
if (new_val >= mod) {
new_val -= mod;
}
}
dp.swap(ndp);
}
ll result = (dp[0][0] + dp[0][1]) % mod;
cout << result << "\n";
return 0;
}
/*
5 5
1 2
2 3
3 4
4 5
1 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
5 5 1 2 2 3 3 4 4 5 1 5
output:
16
result:
ok 1 number(s): "16"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
3 0
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
2 1 1 2
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
4 6 1 2 1 3 1 4 2 3 2 4 3 4
output:
6
result:
ok 1 number(s): "6"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
1 0
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
4 5 1 2 1 3 1 4 2 3 3 4
output:
8
result:
ok 1 number(s): "8"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
5 3 1 3 1 4 1 5
output:
24
result:
ok 1 number(s): "24"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
5 0
output:
32
result:
ok 1 number(s): "32"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
6 3 1 2 3 4 3 6
output:
40
result:
ok 1 number(s): "40"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
6 0
output:
64
result:
ok 1 number(s): "64"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
7 3 2 3 3 6 6 7
output:
80
result:
ok 1 number(s): "80"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
7 0
output:
128
result:
ok 1 number(s): "128"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
20 30 1 7 1 9 1 12 1 13 2 6 2 17 3 13 4 12 4 15 4 17 6 10 6 17 7 8 7 18 8 14 9 13 10 16 10 17 12 14 13 15 13 16 13 20 14 16 14 18 14 20 15 17 15 18 15 19 15 20 16 17
output:
524288
result:
ok 1 number(s): "524288"
Test #14:
score: -100
Wrong Answer
time: 0ms
memory: 3660kb
input:
20 73 1 4 1 9 1 13 2 6 2 7 2 12 2 14 2 18 2 19 3 6 3 10 3 12 3 14 3 16 3 17 3 18 4 6 4 7 4 11 4 14 4 15 4 18 4 19 5 6 5 7 5 9 5 10 5 12 5 14 5 15 5 17 5 18 5 19 5 20 6 12 6 13 6 15 6 16 6 17 7 9 7 16 7 19 8 11 8 15 8 16 8 20 9 10 9 12 9 17 9 20 10 11 10 12 10 14 10 16 10 17 10 18 11 12 11 20 12 13 1...
output:
525312
result:
wrong answer 1st numbers differ - expected: '524288', found: '525312'