QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67982#5169. 夹娃娃yllcm40 2974ms619048kbC++1712.0kb2022-12-13 20:17:372022-12-13 20:17:40

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-13 20:17:40]
  • 评测
  • 测评结果:40
  • 用时:2974ms
  • 内存:619048kb
  • [2022-12-13 20:17:37]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long    
#define ull unsigned long long
#define db double
#define ldb long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define FR first
#define SE second
#define il inline 
#define re register 
using namespace std;
inline int read() {
    int x = 0; bool op = 0;
    char c = getchar();
    while(!isdigit(c))op |= (c == '-'), c = getchar();
    while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return op ? -x : x;
}
const int N = 5e3 + 10;
const int M = 2080;
int n, Q, p;
namespace S1 {
    const int P = 998244353;
    int B, T;
    il void add(int &a, int b) {a += b; a >= P ? a -= P : 0;}
    il void sub(int &a, int b) {a -= b; a < 0 ? a += P : 0;}
    il int ksm(int x, int k) {
        int res = 1;
        for(int pw = x; k; (k & 1) ? res = 1ll * res * pw % P : 0, pw = 1ll * pw * pw % P, k >>= 1);
        return res;
    }
    int f[20][N], L[10], R[10], st[N][N], pd[N], tmp[N];
    struct Poly {
        int f[N];
        il Poly operator * (const int &x) {
            Poly res;
            for(re int i = 0; i <= M; i++) {
                res.f[i] = 1ll * f[i] * x % P;
            }
            return res;
        }
        il Poly operator * (const Poly &x) {
            Poly res;
            for(re int i = 0; i <= M; i++) {
                res.f[i] = 1ll * f[i] * x.f[i] % P;
            }
            return res;
        }
        il Poly operator + (const Poly &x) {
            Poly res;
            for(re int i = 0; i <= M; i++) {
                res.f[i] = (f[i] + x.f[i]) % P;
            }
            return res;
        }
    }g[20], h[20], pg[5][600][1 << 4], th[5][1 << 4];
    char str[N];
    void MAIN() {
        for(re int i = 1; i <= n; i++) {
            int k = read();
            f[i][0] = 1;
            for(re int j = 1; j <= k; j++) {
                int b = read(), c = read();
                for(re int t = 520; ~t; t--) {
                    if(f[i][t] == 0)continue;
                    for(re int p = 1; p <= c && t + p * b <= 520; p++) {
                        add(f[i][t + p * b], f[i][t]);
                    }
                }
            }
            // for(int t = 0; t <= 520; t++) {
            //     if(f[i][t])printf("f:%d %d %d\n", i, t, f[i][t]);
            // }
        }
        for(re int i = 1; i <= n; i++) {
            for(re int j = 0; j <= M; j++) {
                int w = 1;
                for(re int k = 0; k <= 520; k++) {
                    add(h[i].f[j], 1ll * f[i][k] * w % P);
                    w = 1ll * w * j % P;
                }
            }
        }
        pd[0] = 1;
        for(re int i = 0; i <= M; i++) {
            for(re int j = i; j >= 0; j--) {
                add(pd[j + 1], pd[j]);
                pd[j] = (P - 1ll * pd[j] * i % P) % P;
            }
        }
        for(re int i = 0; i <= M; i++) {
            int coef = 1;
            for(re int j = 0; j <= M; j++) {
                if(j != i)coef = 1ll * coef * ((i - j + P) % P) % P;
            }
            coef = ksm(coef, P - 2);
            memcpy(st[i], pd, sizeof(pd));
            for(re int j = M + 1; j; j--)add(st[i][j - 1], 1ll * i * st[i][j] % P);
            for(re int j = 0; j <= M; j++)st[i][j] = st[i][j + 1]; st[i][M + 1] = 0;
            for(re int j = 0; j <= M; j++)st[i][j] = 1ll * st[i][j] * coef % P;
            // for(re int j = 1; j <= M; j++)add(st[i][j], st[i][j - 1]);
        }
        B = 4;
        for(re int i = 1; i <= n; i += B)L[++T] = i, R[T] = min(n, i + B - 1);
        for(int i = 1; i <= T; i++) {
            int l = R[i] - L[i] + 1;
            for(int j = 0; j < (1 << l); j++) {
                for(int k = 0; k <= M; k++)th[i][j].f[k] = 1;
                for(int k = 0; k < l; k++) {
                    if(j >> k & 1)continue;
                    th[i][j] = th[i][j] * h[k + L[i]];
                }
                for(int t = 0; t <= 520; t++) {
                    tmp[t] = 0;
                    for(int p = 0; p <= M; p++) {  
                        add(tmp[t], 1ll * th[i][j].f[p] * st[p][t] % P);
                    }
                }
                for(int p = 0; p <= M; p++) {
                    int w = 1; th[i][j].f[p] = 0;
                    for(int t = 0; t <= 520; t++) {
                        add(th[i][j].f[p], 1ll * w * tmp[t] % P);
                        w = 1ll * w * p % P;
                    }
                }
            }
        }
        for(re int i = 0; i <= 520; i++) {
            for(re int j = 0; j <= M; j++) {
                int w = ksm(j, i);
                for(re int k = 1; k <= n; k++) {
                    add(g[k].f[j], 1ll * f[k][i] * w % P);
                }
            }
            for(re int j = 1; j <= T; j++) {
                int l = R[j] - L[j] + 1;
                for(re int s = 0; s < (1 << l); s++) {
                    if((i + 1) * __builtin_popcount(s) > 520)continue;
                    pg[j][i][s] = th[j][s];
                    for(re int k = 0; k < l; k++) {
                        if(s >> k & 1)pg[j][i][s] = pg[j][i][s] * g[k + L[j]];
                    }
                    if(__builtin_popcount(s) & 1)pg[j][i][s] = pg[j][i][s] * (P - 1);
                }
                for(re int k = 0; k < l; k++) {
                    for(re int s = 0; s < (1 << l); s++) {
                        if(s >> k & 1) {
                            pg[j][i][s] = pg[j][i][s] + pg[j][i][s ^ (1 << k)];
                        }
                    }
                }
            }
        }
        for(int i = 0; i <= M; i++) {
            for(int j = 1; j <= M; j++) {
                add(st[i][j], st[i][j - 1]);
            }
        }
        // int _TIME = 0;
        while(Q--) {
            scanf("%s", str + 1);
            int m = read(), d = read(), sum = 0, res = 0;
            for(re int i = 1; i <= n; i++)if(str[i] == '1')sum += d;
            if(sum > m) {printf("0\n"); continue;}
            Poly now;
            for(re int i = 0; i <= M; i++)now.f[i] = 1;
            for(re int j = 1; j <= T; j++) {
                int s = 0, l = R[j] - L[j] + 1;
                for(re int k = 0; k < l; k++) {
                    if(str[k + L[j]] == '1')s |= (1 << k);
                }
                now = now * pg[j][d - 1][s];
            }
            // _TIME -= clock();
            for(re int i = 0; i <= M; i++) {
                // add(res, 1ll * now.f[i] * st[i][m] % P);
                add(res, 1ll * now.f[i] * st[i][m] % P);
            }
            // _TIME += clock();
            printf("%d\n", res);
        }
        // cerr << 1.0 * _TIME / CLOCKS_PER_SEC << endl;
        return ;
    }
};
namespace S2 {
    const int P = 1e9 + 7;
    int B, T;
    il void add(int &a, int b) {a += b; a >= P ? a -= P : 0;}
    il void sub(int &a, int b) {a -= b; a < 0 ? a += P : 0;}
    il int ksm(int x, int k) {
        int res = 1;
        for(int pw = x; k; (k & 1) ? res = 1ll * res * pw % P : 0, pw = 1ll * pw * pw % P, k >>= 1);
        return res;
    }
    int f[20][N], L[10], R[10], st[N][N], pd[N];
    struct Poly {
        int f[N];
        il Poly operator * (const int &x) {
            Poly res;
            for(re int i = 0; i <= M; i++) {
                res.f[i] = 1ll * f[i] * x % P;
            }
            return res;
        }
        il Poly operator * (const Poly &x) {
            Poly res;
            for(re int i = 0; i <= M; i++) {
                res.f[i] = 1ll * f[i] * x.f[i] % P;
            }
            return res;
        }
        il Poly operator + (const Poly &x) {
            Poly res;
            for(re int i = 0; i <= M; i++) {
                res.f[i] = (f[i] + x.f[i]) % P;
            }
            return res;
        }
    }g[20], h[20], pg[5][600][1 << 4];
    char str[N];
    void MAIN() {
        for(re int i = 1; i <= n; i++) {
            int k = read();
            f[i][0] = 1;
            for(re int j = 1; j <= k; j++) {
                int b = read(), c = read();
                for(re int t = 520; ~t; t--) {
                    if(f[i][t] == 0)continue;
                    for(re int p = 1; p <= c && t + p * b <= 520; p++) {
                        add(f[i][t + p * b], f[i][t]);
                    }
                }
            }
            // for(int t = 0; t <= 520; t++) {
            //     if(f[i][t])printf("f:%d %d %d\n", i, t, f[i][t]);
            // }
        }
        for(re int i = 1; i <= n; i++) {
            for(re int j = 0; j <= M; j++) {
                int w = 1;
                for(re int k = 0; k <= 520; k++) {
                    add(h[i].f[j], 1ll * f[i][k] * w % P);
                    w = 1ll * w * j % P;
                }
            }
        }
        B = 4;
        for(re int i = 1; i <= n; i += B)L[++T] = i, R[T] = min(n, i + B - 1);
        for(re int i = 0; i <= 520; i++) {
            for(re int j = 0; j <= M; j++) {
                int w = ksm(j, i);
                for(re int k = 1; k <= n; k++) {
                    add(g[k].f[j], 1ll * f[k][i] * w % P);
                }
            }
            for(re int j = 1; j <= T; j++) {
                int l = R[j] - L[j] + 1;
                for(re int s = 0; s < (1 << l); s++) {
                    if((i + 1) * __builtin_popcount(s) > 520)continue;
                    for(re int k = 0; k <= M; k++)pg[j][i][s].f[k] = 1;
                    for(re int k = 0; k < l; k++) {
                        if(s >> k & 1)pg[j][i][s] = pg[j][i][s] * g[k + L[j]];
                        else pg[j][i][s] = pg[j][i][s] * h[k + L[j]];
                    }
                    if(__builtin_popcount(s) & 1)pg[j][i][s] = pg[j][i][s] * (P - 1);
                }
                for(re int k = 0; k < l; k++) {
                    for(re int s = 0; s < (1 << l); s++) {
                        if(s >> k & 1) {
                            pg[j][i][s] = pg[j][i][s] + pg[j][i][s ^ (1 << k)];
                        }
                    }
                }
            }
        }
        pd[0] = 1;
        for(re int i = 0; i <= M; i++) {
            for(re int j = i; j >= 0; j--) {
                add(pd[j + 1], pd[j]);
                pd[j] = (P - 1ll * pd[j] * i % P) % P;
            }
        }
        for(re int i = 0; i <= M; i++) {
            int coef = 1;
            for(re int j = 0; j <= M; j++) {
                if(j != i)coef = 1ll * coef * ((i - j + P) % P) % P;
            }
            coef = ksm(coef, P - 2);
            memcpy(st[i], pd, sizeof(pd));
            for(re int j = M + 1; j; j--)add(st[i][j - 1], 1ll * i * st[i][j] % P);
            for(re int j = 0; j <= M; j++)st[i][j] = st[i][j + 1]; st[i][M + 1] = 0;
            for(re int j = 0; j <= M; j++)st[i][j] = 1ll * st[i][j] * coef % P;
            for(re int j = 1; j <= M; j++)add(st[i][j], st[i][j - 1]);
        }
        // int _TIME = 0;
        while(Q--) {
            scanf("%s", str + 1);
            int m = read(), d = read(), sum = 0, res = 0;
            for(re int i = 1; i <= n; i++)if(str[i] == '1')sum += d;
            if(sum > m) {printf("0\n"); continue;}
            Poly now;
            for(re int i = 0; i <= M; i++)now.f[i] = 1;
            for(re int j = 1; j <= T; j++) {
                int s = 0, l = R[j] - L[j] + 1;
                for(re int k = 0; k < l; k++) {
                    if(str[k + L[j]] == '1')s |= (1 << k);
                }
                now = now * pg[j][d - 1][s];
            }
            // _TIME -= clock();
            for(re int i = 0; i <= M; i++) {
                // add(res, 1ll * now.f[i] * st[i][m] % P);
                add(res, 1ll * now.f[i] * st[i][m] % P);
            }
            // _TIME += clock();
            printf("%d\n", res);
        }
        return ;
    }
};
int main() { 
    n = read(); Q = read(); p = read();
    if(p == 998244353)S1::MAIN();
    else S2::MAIN();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 158ms
memory: 66956kb

input:

1 521 998244353
39 520 520 11 22 414 8 95 18 229 356 26 407 316 10 24 26 19 61 11 130 482 476 420 15 192 193 208 24 19 233 494 217 275 294 26 28 439 20 272 277 28 198 5 335 22 8 28 17 154 78 6 13 175 17 2 5 477 256 200 4 1 36 427 371 439 23 10 65 426 25 24 27 121 29 28 13 12 453
0 520 1
1 519 1
1 51...

output:

38813347
922143638
98254957
38813343
922143633
38813338
98254946
922143620
98254933
922143604
38813302
38813288
922143562
38813247
38813220
38813188
38813150
98254715
38813047
922143273
98254516
38812814
922142999
98254191
922142723
38812257
38812058
98253436
922141847
38811240
922141173
38810463
38...

result:

ok 521 lines

Test #2:

score: 0
Accepted
time: 217ms
memory: 87296kb

input:

2 1561 998244353
151 520 520 511 30 121 396 25 16 113 11 6 175 242 20 8 5 61 13 518 447 404 8 220 177 4 19 18 15 70 233 9 14 26 512 17 9 9 19 30 8 495 20 13 27 277 22 396 14 4 29 345 442 19 25 14 5 16 295 19 65 134 10 10 296 245 6 7 30 253 15 187 26 482 454 28 414 170 404 11 27 27 25 13 509 1 5 291 ...

output:

883965618
144348435
762074635
112296779
385763651
821718611
673974966
879750066
927942969
136450507
436584627
612945970
768262217
613885343
39304132
852224740
215596261
151746110
965953558
969833936
664053020
458247365
881060255
878484499
781573019
616944059
850325449
296113117
674829177
887392623
6...

result:

ok 1561 lines

Subtask #2:

score: 13
Accepted

Dependency #1:

100%
Accepted

Test #3:

score: 13
Accepted
time: 346ms
memory: 128464kb

input:

3 4160 998244353
444 520 520 26 332 29 183 25 479 175 14 13 16 1 447 2 293 4 20 64 472 491 11 21 259 75 22 390 401 8 508 405 3 137 4 15 154 164 1 484 13 257 14 44 20 7 13 26 15 26 432 14 9 478 24 18 10 22 28 8 21 260 25 431 22 7 6 20 26 8 27 239 19 1 134 2 322 16 225 6 42 517 6 197 407 268 500 433 5...

output:

516056999
990096150
497048298
345860798
899328070
577475723
191997503
533625761
516056999
863614705
652318084
514747110
811600228
92531482
136793394
218097588
352553395
821305819
739754364
569418540
402235631
844207347
78271439
896568337
516056999
243958673
201200148
634787992
552693501
893938722
98...

result:

ok 4160 lines

Test #4:

score: 0
Accepted
time: 566ms
memory: 207892kb

input:

4 8320 998244353
303 520 520 288 10 15 24 306 456 495 124 20 419 24 473 7 462 365 405 4 30 1 29 15 25 29 324 407 14 30 184 425 451 6 414 7 417 155 12 18 20 2 475 78 174 467 23 300 26 13 15 345 319 10 27 497 25 21 51 24 485 359 268 87 20 509 13 18 261 13 6 20 237 305 26 245 330 514 29 21 197 25 345 1...

output:

857239630
694514392
340827658
834331936
573150389
560202020
302111919
422193966
147386541
201821565
447255018
322990367
192787601
197802108
461775999
315804262
316164169
338416167
240429979
359914423
321666890
541700460
506123940
701447430
823947537
621301718
62107305
163486246
380210777
211911024
9...

result:

ok 8320 lines

Test #5:

score: 0
Accepted
time: 1669ms
memory: 208060kb

input:

4 52099 998244353
103 520 520 12 485 23 1 337 514 374 486 210 29 29 1 19 299 3 11 11 22 282 14 12 9 341 286 18 501 3 3 29 364 264 477 22 6 434 14 11 117 22 8 30 268 22 28 10 12 311 58 14 15 234 177 17 238 71 64 14 1 396 23 492 4 1 13 6 8 197 4 7 27 11 370 19 242 12 13 20 185 432 399 24 32 2 516 36 4...

output:

51769626
700322830
226311543
862334239
622358370
748398901
344771107
59670026
558254404
668258250
91212841
493756321
360353830
36696310
321158867
563614481
998042994
565120563
709404804
783802088
511531306
396636746
513730575
451308648
594545675
544172685
900482622
791631384
368742309
537404993
6927...

result:

ok 52099 lines

Subtask #3:

score: 14
Accepted

Dependency #2:

100%
Accepted

Test #6:

score: 14
Accepted
time: 1038ms
memory: 291736kb

input:

7 52099 998244353
375 520 520 5 295 315 14 25 329 20 137 280 8 286 20 23 15 1 2 21 48 2 16 11 481 18 3 343 18 75 26 103 449 190 270 451 241 15 18 16 142 8 105 159 446 418 15 76 24 384 23 17 514 504 20 497 18 15 367 11 268 425 449 15 456 8 308 517 468 17 6 8 308 22 1 4 465 14 125 434 111 28 384 22 31...

output:

749892128
0
0
0
0
0
260438093
290693060
0
448909491
0
219322656
387184158
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
619977128
447966638
0
681308080
0
0
681648223
0
0
214156868
691259433
912802497
929329058
63245351
0
944326280
86464571
0
0
815255897
146151793
0
0
0
0
0
863159042
312726953
980444251
0
600279...

result:

ok 52099 lines

Test #7:

score: 0
Accepted
time: 1999ms
memory: 371492kb

input:

8 52099 998244353
40 520 520 460 30 231 518 11 249 12 19 4 393 288 9 15 27 285 59 19 26 211 6 379 410 422 405 380 375 456 371 319 27 26 402 140 24 70 20 271 312 319 29 368 310 16 456 9 291 13 508 26 65 5 22 401 3 365 127 211 3 17 98 24 290 26 171 409 28 17 9 516 93 2 18 24 25 181 2 6 141
315 520 520...

output:

0
121472646
0
0
868501509
0
0
0
0
311676707
0
0
0
0
0
0
708345252
0
0
0
0
186486401
0
0
467064132
0
0
154691791
0
0
0
0
0
0
0
798981714
0
0
733168043
733528284
0
0
0
80512352
0
235570507
0
0
0
0
78997839
0
0
452560485
0
0
0
0
46384876
0
0
433696320
653100986
0
299555135
0
593915472
0
0
534577853
0
0...

result:

ok 52099 lines

Test #8:

score: 0
Accepted
time: 2039ms
memory: 371516kb

input:

8 52099 998244353
27 520 520 137 195 11 296 397 165 52 434 18 30 7 392 364 205 347 226 175 292 16 69 8 24 54 15 26 29 121 75 23 22 321 11 88 3 19 100 54 118 5 30 2 30 77 11 420 20 4 4 19 1 24 6
117 520 520 8 96 357 13 23 4 147 415 113 86 499 18 14 23 12 15 431 27 3 406 8 13 26 23 102 19 12 24 26 357...

output:

611640132
300436849
327055017
766720771
275032937
904593053
463655376
369893628
214854225
929700933
174664089
812989004
625111481
812138767
845347445
833479053
735408106
735408106
503061044
986829167
458414549
917511270
397433661
828381114
545635279
261016968
690895096
234181435
793843962
377062472
...

result:

ok 52099 lines

Subtask #4:

score: 10
Accepted

Test #9:

score: 10
Accepted
time: 2794ms
memory: 618852kb

input:

15 52099 998244353
1 9 3
1 9 4
1 9 2
1 8 10
1 4 4
1 3 1
1 2 5
1 4 9
1 1 4
1 9 4
1 7 6
1 1 6
1 2 5
1 5 2
1 3 5
101000000001010 516 1
010001001010101 520 2
000000101000001 519 2
101011111100011 518 1
010110001000111 520 2
000110111100111 516 1
000100101001011 519 3
000111001010011 518 1
00001110010111...

output:

993379058
496689529
866368587
797687294
481245176
481245176
39022588
269889529
552778235
769822588
331666941
99789529
903956470
112750588
756797435
519045176
870912000
361582588
594280447
494747647
597778941
178845176
435456000
493445999
461733882
308912117
271186941
496689529
919511294
85533882
894...

result:

ok 52099 lines

Test #10:

score: 0
Accepted
time: 2893ms
memory: 619048kb

input:

15 52099 998244353
1 444 1
1 184 2
1 427 1
1 23 1
1 513 2
1 413 4
1 304 2
1 214 5
1 108 2
1 304 1
1 283 5
1 465 1
1 277 1
1 57 2
1 160 4
111010111100101 520 25
010010011100110 520 3
010000011011000 519 36
110011011100110 516 21
010110001101101 516 42
100001101000111 520 31
110001100010001 519 10
110...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 52099 lines

Test #11:

score: 0
Accepted
time: 2974ms
memory: 619016kb

input:

15 52099 998244353
1 5 5
1 43 5
1 25 5
1 30 3
1 34 4
1 32 3
1 45 4
1 27 4
1 30 5
1 22 2
1 26 4
1 5 4
1 23 2
1 13 1
1 3 3
010111011010001 519 2
101000001100000 518 66
001011100110000 518 52
001100000000010 520 42
000110000110100 518 40
100011100010011 518 34
101000111100000 520 9
101010011100100 519 ...

output:

11101681
0
0
0
1142004
0
36064398
16061763
2645108
0
0
10591435
746157
1803184
0
0
16192453
0
0
0
0
20456968
0
3582238
805462
14505464
0
0
0
0
0
0
0
26667881
0
0
0
0
0
0
4674341
0
0
0
0
0
0
0
0
0
0
0
21963213
8597667
4334676
43539633
0
0
0
0
0
2382160
5712673
2788111
1352473
0
0
0
0
0
0
0
0
47306134...

result:

ok 52099 lines

Test #12:

score: 0
Accepted
time: 2234ms
memory: 414684kb

input:

10 52099 998244353
1 5 1
1 23 1
1 27 4
1 19 4
1 12 2
1 30 5
1 28 2
1 16 4
1 30 3
1 6 5
0011010111 519 23
0000001001 517 49
0010110011 517 60
0001111100 520 44
1101101010 518 37
1010011010 519 33
0010010001 519 43
0110001001 517 29
1110101110 518 38
1011010010 520 49
0000000011 520 29
0011111011 518 ...

output:

37275
0
0
0
0
0
0
0
0
0
79991
0
0
0
15342
0
0
0
20344
0
56202
0
0
0
50043
0
0
0
181532
0
0
0
0
52937
0
0
0
0
0
55478
56473
0
255272
0
22226
0
0
18671
236899
0
16685
0
0
31629
0
0
0
0
0
0
87684
0
0
84149
0
0
0
127178
0
0
0
0
0
0
0
0
0
0
0
159291
0
0
0
41794
70377
83979
0
0
56097
0
106432
0
0
0
0
1131...

result:

ok 52099 lines

Test #13:

score: 0
Accepted
time: 2298ms
memory: 394116kb

input:

9 52099 998244353
1 18 1
1 8 3
1 36 5
1 47 2
1 47 3
1 34 3
1 38 5
1 35 5
1 45 5
110110111 520 8
001110101 519 42
010101000 516 37
101001001 516 9
110111111 518 33
100111010 519 41
000010000 520 116
010110110 519 25
001011011 517 17
001100000 517 104
000010101 518 79
111100110 517 34
011100111 516 1
...

output:

5039
4726
0
24816
0
0
24712
0
19695
0
3683
0
13040
0
10500
23330
0
0
52779
0
3146
3023
8773
9949
0
0
0
11047
0
30494
0
6016
7291
0
6836
16605
0
0
0
0
6209
14419
0
0
0
14987
0
0
0
0
0
13850
0
0
0
0
4210
11509
0
43740
0
21261
0
74429
0
0
15553
0
5876
33640
0
0
0
12734
0
14637
0
39701
2277
0
0
0
0
0
0
...

result:

ok 52099 lines

Test #14:

score: 0
Accepted
time: 167ms
memory: 66828kb

input:

1 1000 998244353
1 5 1
0 516 28
1 517 106
1 517 22
0 519 4
0 516 37
0 518 10
1 517 62
0 519 32
1 518 58
1 519 72
1 516 82
1 520 56
1 516 59
1 520 79
0 517 122
1 517 2
1 517 53
0 518 93
0 520 149
1 520 86
0 520 53
1 517 120
1 518 41
1 517 94
0 519 76
0 517 46
1 520 48
0 519 31
0 519 4
0 516 24
0 516 ...

output:

2
0
0
2
2
2
0
2
0
0
0
0
0
0
2
1
0
2
2
0
2
0
0
0
2
2
0
2
2
2
2
0
2
2
2
2
0
0
0
2
2
0
0
2
2
2
2
0
0
2
0
2
0
0
2
2
0
2
2
0
0
2
2
2
0
0
2
0
0
2
0
2
0
0
2
0
0
0
0
2
2
0
0
0
1
2
2
2
2
2
2
2
2
0
0
2
2
2
0
2
2
0
0
2
0
2
0
2
0
2
2
0
0
0
0
0
2
2
2
2
2
0
2
0
0
0
0
0
2
2
2
0
2
0
2
0
0
2
2
0
0
2
2
0
2
0
2
2
0
0
...

result:

ok 1000 lines

Subtask #5:

score: 0
Wrong Answer

Dependency #3:

100%
Accepted

Test #15:

score: 0
Wrong Answer
time: 2787ms
memory: 618892kb

input:

15 52099 998244353
187 520 520 21 25 475 247 297 180 3 22 17 13 8 362 153 23 203 492 444 270 7 17 12 27 30 5 316 281 441 11 518 34 10 23 12 403 213 467 351 22 178 8 54 37 28 22 29 209 209 25 16 286 447 7 6 25 334 14 25 29 304 9 347 26 63 199 470 72 25 151 29 289 38 3 484 16 202 28 410 25 1 16 25 6 1...

output:

845721892
153997377
96678937
517808019
786032838
576254501
881486326
803902892
635490334
355049473
142301475
241982975
534349844
410093109
210694743
403072824
464410352
986011158
296843831
407473919
812438509
121924289
790654824
502357668
293839191
36455582
428896992
232627499
527240513
384450355
64...

result:

wrong answer 1st lines differ - expected: '201142254', found: '845721892'

Subtask #6:

score: 0
Skipped

Dependency #4:

100%
Accepted

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%