QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#862039#2824. 找树strcmpWA 405ms34304kbC++142.5kb2025-01-18 21:22:022025-01-18 21:22:35

Judging History

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

  • [2025-01-18 21:22:35]
  • 评测
  • 测评结果:WA
  • 用时:405ms
  • 内存:34304kb
  • [2025-01-18 21:22:02]
  • 提交

answer

#include <bits/stdc++.h>
#define X first
#define Y second
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int ll;
using ull = unsigned long long int;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pq = priority_queue<int>;
using ld = double;
constexpr int maxn = 3e5 + 10, mod = 998244353, K = 40;
constexpr ll inf = 1e18; int n, m, len; char O[maxn]; ll b[75][75], a[75][75][4105], c[4105];
void fwt(ll* f, int n, int op) {
    for (int i = 1, p = 1; p <= len; i <<= 1, p++) {
        if (O[p] == '|') for (int j = 0; j < n; j += i << 1) rep(k, 0, i - 1) f[i + j + k] = (f[i + j + k] + (op == 1 ? f[j + k] : mod - f[j + k])) % mod;
        else if (O[p] == '&') for (int j = 0; j < n; j += i << 1) rep(k, 0, i - 1) f[j + k] = (f[j + k] + (op == 1 ? f[i + j + k] : mod - f[i + j + k])) % mod;
        else for (int j = 0; j < n; j += i << 1) rep(k, 0, i - 1) {
            int u = f[j + k], v = f[i + j + k];
            f[j + k] = (u + v) % mod, f[i + j + k] = (u - v) % mod;
            if (op == -1) f[j + k] = (ll)f[j + k] * 499122177 % mod, f[i + j + k] = (ll)f[i + j + k] % 499122177 % mod;
        }
    }
}
ll det() {
    ll ans = 1;
    rep(i, 1, n - 1) {
    	rep(j, i + 1, n - 1) if (!b[i][i] && b[j][i]) { ans = mod - ans; swap(b[i], b[j]); break; }
    	if (!b[i][i]) return 0;
        rep(j, i + 1, n - 1) {
            while (b[i][i]) {
                ll w = b[j][i] / b[i][i];
                rep(k, i, n - 1) b[j][k] = (b[j][k] - b[i][k] * w % mod + mod) % mod;
                swap(b[i], b[j]); ans = mod - ans;
            }
            swap(b[i], b[j]); ans = mod - ans;
        }
    }
    rep(i, 1, n - 1) ans = ans * b[i][i] % mod;
    return ans;
}
int main() {
    scanf("%d%d%s", &n, &m, O + 1); len = strlen(O + 1);
    for (int i = 1, u, v, w; i <= m; i++) {
        scanf("%d%d%d", &u, &v, &w);
        a[u][u][w] = (a[u][u][w] + 1) % mod, a[v][v][w] = (a[v][v][w] + 1) % mod;
        a[u][v][w] = (a[u][v][w] + mod - 1) % mod, a[v][u][w] = (a[v][u][w] + mod - 1) % mod;
    }
    rep(i, 1, n - 1) rep(i, 1, n - 1) fwt(a[i][i], 1 << len, 1);
    rep(w, 0, 1 << len) {
        rep(i, 1, n) rep(j, 1, n) b[i][j] = a[i][j][w];
        c[w] = det();
    }
    fwt(c, 1 << len, -1);
    per(i, (1 << len) - 1, 0) if (c[i]) printf("%d\n", i), exit(0);
    puts("-1");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 355ms
memory: 9252kb

input:

70 100
&&&&&&&&&&&&
59 1 577
11 18 513
41 11 6
7 33 1
25 26 577
3 57 516
28 5 3
13 56 0
2 32 7
66 53 517
42 31 519
41 34 70
37 54 579
24 15 512
70 32 512
51 49 64
55 19 69
3 31 517
24 8 582
44 45 513
47 58 517
47 41 577
33 22 519
57 41 0
70 50 67
3 6 6
14 43 6
21 1 579
32 27 576
62 7 514
39 36 69
12...

output:

-1

result:

ok single line: '-1'

Test #2:

score: 0
Accepted
time: 360ms
memory: 9004kb

input:

70 100
|&&&&|&&&^&&
70 50 200
51 46 9
48 33 163
14 64 137
53 54 96
32 24 160
7 22 8
40 66 192
12 22 74
20 25 66
7 40 97
27 13 192
3 15 96
43 16 195
23 6 74
7 34 33
5 5 98
12 26 99
44 38 8
27 44 32
10 67 42
19 12 234
6 39 65
27 24 8
58 13 106
37 69 32
4 2 163
33 65 168
3 3 107
56 65 8
42 53 137
32 53...

output:

-1

result:

ok single line: '-1'

Test #3:

score: -100
Wrong Answer
time: 405ms
memory: 34304kb

input:

70 5000
^&&&&|^&^&&|
70 55 35
32 4 2338
1 45 33
69 4 2337
55 51 2338
26 46 2050
8 5 33
16 51 35
32 10 1
18 67 257
12 37 2307
34 6 2051
30 10 33
21 35 2082
4 27 34
12 4 2337
44 34 2082
11 17 2338
1 2 289
22 2 34
39 68 2304
11 48 289
44 26 2080
57 12 2306
69 15 2338
16 65 2
51 67 2048
1 5 291
64 48 28...

output:

2403

result:

wrong answer 1st lines differ - expected: '2339', found: '2403'