QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#491727#6555. Sets May Be GoodpandapythonerWA 0ms3640kbC++232.4kb2024-07-25 21:35:462024-07-25 21:35:46

Judging History

你现在查看的是最新测评结果

  • [2024-07-25 21:35:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3640kb
  • [2024-07-25 21:35:46]
  • 提交

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 (g[u][v]) {
        self_loop[v] ^= 1;
    }
    if (self_loop[v]) {
        self_loop[u] ^= 1;
        g[u][v] ^= 1;
        g[v][u] ^= 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

*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

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: 3576kb

input:

3 0

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

2 1
1 2

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3640kb

input:

4 6
1 2
1 3
1 4
2 3
2 4
3 4

output:

8

result:

wrong answer 1st numbers differ - expected: '6', found: '8'