QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#491788#6553. Shared Memory SwitchpandapythonerRE 0ms0kbC++232.5kb2024-07-25 22:07:112024-07-25 22:07:12

Judging History

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

  • [2024-07-25 22:07:12]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-25 22:07:11]
  • 提交

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

*/

详细

Test #1:

score: 0
Runtime Error

input:

14 5
1 1 1 2 2 2 -1 1 -1 1 -1 1 -1 1

output:


result: