QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#71828#2579. 开关He_Ren100 ✓13ms4032kbC++231.2kb2023-01-12 01:27:272023-01-12 01:31:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-12 01:31:42]
  • 评测
  • 测评结果:100
  • 用时:13ms
  • 内存:4032kb
  • [2023-01-12 01:27:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 1e2 + 5;
const int MAXP = 5e4 + 5;
const int mod = 998244353;

inline void add_mod(int &a, int b) {
    a += b;

    if (a >= mod)
        a -= mod;
}

inline ll pw(ll a, ll b) {
    ll res = 1;

    while (b) {
        if (b & 1)
            res = res * a % mod;

        a = a * a % mod;
        b >>= 1;
    }

    return res;
}

int s[MAXN], p[MAXN];
int f[MAXP][2];

int main(void) {
    int n;
    scanf("%d", &n);

    for (int i = 1; i <= n; ++i)
        scanf("%d", &s[i]);

    for (int i = 1; i <= n; ++i)
        scanf("%d", &p[i]);

    int sump = accumulate(p + 1, p + n + 1, 0);

    f[0][0] = 1;

    for (int i = 1; i <= n; ++i)
        for (int j = sump; j >= 0; --j)
            for (int k = 0; k <= 1; ++k)
                if (f[j][k])
                    add_mod(f[j + p[i]][k ^ s[i]], f[j][k]);

    int ans = 0;

    for (int i = 0; i <= sump; ++i)
        if (f[i][1])
            ans = (ans + (ll)sump * pw(i, mod - 2) % mod * f[i][1]) % mod;

    printf("%d", ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 2ms
memory: 3812kb

input:

2
1 1
23723 26273

output:

877668810

result:

ok single line: '877668810'

Test #2:

score: 10
Accepted
time: 2ms
memory: 3540kb

input:

2
1 0
18216 31771

output:

489970511

result:

ok single line: '489970511'

Test #3:

score: 10
Accepted
time: 2ms
memory: 3748kb

input:

8
1 1 0 1 1 0 1 0
1270 10205 3901 3809 8931 2530 11580 7773

output:

193550909

result:

ok single line: '193550909'

Test #4:

score: 10
Accepted
time: 2ms
memory: 3932kb

input:

8
0 1 0 0 0 1 0 0
5929 4817 1939 5783 7039 5771 9785 8934

output:

662840715

result:

ok single line: '662840715'

Test #5:

score: 10
Accepted
time: 3ms
memory: 3660kb

input:

100
0 1 0 1 1 1 0 1 0 1 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0 1 0 1 0 1 1 0 0 1 0 1 0 0 1 1 1 1 0 0 0 1 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 1 0 0 0 0 1 0 1 1 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 1 0 0 0 0 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

186395599

result:

ok single line: '186395599'

Test #6:

score: 10
Accepted
time: 2ms
memory: 3564kb

input:

100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 1 1 1 1 1 2 2 1 2 1 1 2 1 2 1 2 1 2 1 2 2 1 1 1 1 1 2 2 2 2 2 1 2 1 1 1 2 1 1 1 2 2 1 2 2 1 2 ...

output:

507890478

result:

ok single line: '507890478'

Test #7:

score: 10
Accepted
time: 2ms
memory: 3620kb

input:

100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 1 2 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 1 2 2 1 1 2 1 2 2 2 1 1 2 2 1 1 2 1 2 1 2 2 1 1 ...

output:

133411468

result:

ok single line: '133411468'

Test #8:

score: 10
Accepted
time: 0ms
memory: 3640kb

input:

100
0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 1 1 0 0 0 1 1 0 0
24 28 18 19 22 36 35 24 7 19 26 2 31 20 33 11 20 37 11 36 9 28 16 20 46 28 5 20 40 27 13 15 28 7...

output:

988115696

result:

ok single line: '988115696'

Test #9:

score: 10
Accepted
time: 0ms
memory: 3540kb

input:

100
1 1 1 0 1 0 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 0 1 1 0 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 1 0 0 1 0 0 1 0 1 1 0 1 0 0 1 1 1 1 0 1 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1 0 0 0 0 1 1 0 1 0 1 0
21 11 16 21 30 35 10 3 15 33 39 7 16 31 24 27 4 15 38 16 6 7 18 11 8 31 8 17 12 20 27 9 44 9 31 ...

output:

124960105

result:

ok single line: '124960105'

Test #10:

score: 10
Accepted
time: 13ms
memory: 4032kb

input:

100
1 0 0 1 0 1 0 0 1 1 1 0 0 1 0 0 0 1 1 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 1 0 1 0 1 0 0 0 0 1 1 1 0 0 1 0 1 1 1 1 0 0 0 0 0 1 0 0 1 1 1 0 1 0 1 1 1 1
840 587 741 540 310 84 284 345 368 251 545 676 754 274 266 97 858 486 108 727 373 283 722 539 29...

output:

114906083

result:

ok single line: '114906083'

Extra Test:

score: 0
Extra Test Passed