QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#240315#6347. XOR Determinantjzh#WA 1ms4064kbC++201.5kb2023-11-05 14:29:272023-11-05 14:29:27

Judging History

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

  • [2023-11-05 14:29:27]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4064kb
  • [2023-11-05 14:29:27]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll Ha = 998244353;

int n;
ll b[5006], c[5005];

ll ksm(ll x, int k) {
    ll ret = 1;
    for (; k; k >>= 1, x = x * x % Ha)
        if (k & 1) ret = ret * x % Ha;
    return ret;
}

void solve() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%lld", &b[i]);
    for (int i = 0; i < n; i++) scanf("%lld", &c[i]);
    
    vector<vector<ll>> a(n, vector<ll>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) a[i][j] = b[i] ^ c[j];
    }
    ll det = 1;
    for (int i = 0; i < n; i++) {
        int k = i;
        for (int j = i + 1; j < n; j++)
            if (a[j][i] > a[k][i]) k = j;
        if (a[k][i] == 0) {
            det = 0;
            break;
        }
        swap(a[i], a[k]);
        if (i != k) {
            det = (-det % Ha + Ha) % Ha;
        }
        det = det * a[i][i] % Ha;
        for (int j = i + 1; j < n; j++) {
            a[i][j] = a[i][j] * ksm(a[i][i], Ha - 2) % Ha;
        }
        for (int j = 0; j < n; j++) {
            if (j != i && a[j][i] != 0) {
                for (int f = i + 1; f < n; f++) {
                    a[j][f] -= a[i][f] * a[j][i] % Ha;
                    a[j][f] = (a[j][f] % Ha + Ha) % Ha;
                }
            }
        }
    }

    printf("%lld\n", det);
}


int main() {
    int ttt;
    scanf("%d", &ttt);
    while (ttt--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2
2 5
4 1
1
1000000000000000001
987467354324283836
4
1 2 3 4
1 2 3 4

output:

21
214139910
998244129

result:

ok 3 number(s): "21 214139910 998244129"

Test #2:

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

input:

1
5
1 2 3 4 5
1 2 3 4 5

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 4064kb

input:

100
10
1107560013855173757 966681903163989710 521892103913129269 1038348664970462356 604430971757857481 1106581500345020431 788162934600883665 124672524392773463 534904853987097709 784497626701360420
402515001559379490 846591944896429860 761680713769800085 722846292535048189 621369111578909792 49581...

output:

486054876
101739322
934932307
374368480
953482340
937767059
120485999
657524919
899419656
885015737
672664609
774774337
803072862
328758519
327005299
750331483
358054736
264759964
679584279
276958561
31137430
36838296
656022871
558248159
668933537
574410087
927294816
993257945
482263052
800615085
11...

result:

wrong answer 1st numbers differ - expected: '548320033', found: '486054876'