QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#275347 | #4782. 完美的旅行 | _LAP_ | 30 | 822ms | 167228kb | C++14 | 3.8kb | 2023-12-04 17:08:58 | 2023-12-04 17:08:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> poly;
const int N = 66, M = 1e4 + 10, MOD = 998244353;
inline int Plus(int a, int b) {return a + b >= MOD ? a + b - MOD : a + b; }
inline int Minus(int a, int b) {return a - b < MOD ? a - b + MOD : a - b; }
inline int ksm(long long a, int b) {
long long r = 1;
while(b) {
if(b & 1) r = r * a % MOD;
b >>= 1, a = a * a % MOD;
}
return r;
}
int rev[M];
inline void NTT(poly &A, int type) {
static const int g = 3;
for(int i = 1; i < A.size(); i ++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) ? A.size() >> 1 : 0);
for(int i = 0; i < A.size(); i ++) if(i < rev[i]) swap(A[i], A[rev[i]]);
for(int h = 2; h <= A.size(); h <<= 1) {
int step = ksm(g, (MOD - 1) / h); if(type == -1) step = ksm(step, MOD - 2);
for(int i = 0; i < A.size(); i += h) {
long long mul = 1;
for(int j = i; j < i + (h >> 1); j ++, mul = mul * step % MOD) {
int u = A[j], v = mul * A[j + (h >> 1)] % MOD;
A[j] = Plus(u, v), A[j + (h >> 1)] = Minus(u, v);
}
}
}
if(type == -1) {
long long inv = ksm(A.size(), MOD - 2);
for(int i = 0; i < A.size(); i ++) A[i] = A[i] * inv % MOD;
}
}
poly operator + (const poly &lhs, const poly &rhs) {
poly res(max(lhs.size(), rhs.size()), 0);
for(int i = 0; i < lhs.size(); i ++) res[i] = Plus(res[i], lhs[i]);
for(int i = 0; i < rhs.size(); i ++) res[i] = Plus(res[i], rhs[i]);
return res;
}
poly operator - (const poly &lhs, const poly &rhs) {
poly res(max(lhs.size(), rhs.size()), 0);
for(int i = 0; i < lhs.size(); i ++) res[i] = lhs[i];
for(int i = 0; i < rhs.size(); i ++) res[i] = Minus(res[i], rhs[i]);
return res;
}
poly operator * (poly lhs, poly rhs) {
int lim = 1, h = 0;
while(lim <= lhs.size() + rhs.size()) lim <<= 1, h ++;
lhs.resize(lim), rhs.resize(lim);
NTT(lhs, 1), NTT(rhs, 1);
for(int i = 0; i < lim; i ++) lhs[i] = 1ll * lhs[i] * rhs[i] % MOD;
NTT(lhs, -1); return lhs;
}
struct matrix {
int n, m, A[N][N];
matrix(int _n = 0, int _m = 0): n(_n), m(_m) {
for(int i = 0; i < n; i ++) for(int j = 0; j < m; j ++) A[i][j] = 0;
}
};
matrix operator * (const matrix &lhs, const matrix &rhs) {
matrix res(lhs.n, rhs.m);
for(int i = 0; i < lhs.n; i ++) for(int j = 0; j < rhs.m; j ++)
for(int k = 0; k < lhs.m; k ++) res.A[i][j] = Plus(res.A[i][j], 1ll * lhs.A[i][k] * rhs.A[k][j] % MOD);
return res;
}
int n, m, f[M][N][N], ans[M][N];
matrix G[M];
int main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> m;
G[1] = matrix(n, n);
for(int i = 0; i < n; i ++) for(int j = 0; j < n; j ++) cin >> G[1].A[i][j];
// for(int i = 2; i <= m; i ++) G[i] = G[i - 1] * G[i - 1];
for(int i = 0; i < n; i ++) f[0][i][i] = 1;
for(int i = 0; i < m; i ++) {
static int T[N][N];
for(int sum = 0; sum < n; sum ++) for(int u = 0; u < n; u ++) T[sum][u] = 0;
for(int sum = 0; sum < n; sum ++) for(int u = 0; u < n; u ++) {
for(int v = 0; v < n; v ++) T[sum][v] = Plus(T[sum][v], 1ll * f[i][sum][u] * G[1].A[u][v] % MOD);
}
for(int j = 0; j < n; j ++) for(int k = 0; k < n; k ++) ans[i + 1][j & k] = Plus(ans[i + 1][j & k], T[j][k]);
for(int sum = 0; sum < n; sum ++) for(int u = 0; u < n; u ++) {
f[i + 1][sum][u] = Plus(f[i + 1][sum][u], T[sum][u]);
for(int w = 0; w < n; w ++) f[i + 1][sum & u & w][w] = Plus(f[i + 1][sum & u & w][w], T[sum][u]);
}
}
int res = 0;
for(int i = 0; i <= m; i ++) for(int j = 0; j < n; j ++) res = res ^ ans[i][j];
cout << res << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 15
Accepted
Test #1:
score: 15
Accepted
time: 3ms
memory: 43676kb
input:
4 20 53674686 128460215 363694167 120271218 578912024 941426068 993595265 587468617 731649477 694107878 355552389 226535630 99325151 243772822 66420647 578481511
output:
588479706
result:
ok 1 number(s): "588479706"
Test #2:
score: 0
Accepted
time: 38ms
memory: 59908kb
input:
16 2000 315391385 70546806 184749201 528239002 741286788 146241680 165603053 41114445 572984599 227056916 305263327 980588113 367160763 155832001 212041467 995977944 491801679 569182307 859668874 327536237 778338213 762819679 11238663 728941676 307395331 62905643 662320291 849065607 550529700 282249...
output:
808196376
result:
ok 1 number(s): "808196376"
Test #3:
score: 0
Accepted
time: 8ms
memory: 44276kb
input:
8 100 681016308 947980964 71683807 222166989 633911431 994577572 50784856 298319502 40710797 455891003 503120116 503880841 988981490 34455718 806388934 589433205 327802386 18831411 193642391 916990555 375690304 69587142 72759137 6300182 494361154 892873815 205578968 352463324 154675154 301940078 523...
output:
625872426
result:
ok 1 number(s): "625872426"
Test #4:
score: 0
Accepted
time: 8ms
memory: 44300kb
input:
8 123 42141734 119453053 338794033 469472517 896943474 997318263 463090940 539752993 498132275 425586204 10331275 799002923 314685843 769975525 214134323 412654359 293167153 22579811 116636410 566990382 581484192 102682042 582694943 865977998 241553124 317584926 931548048 157765288 390446073 1855087...
output:
365380190
result:
ok 1 number(s): "365380190"
Test #5:
score: 0
Accepted
time: 7ms
memory: 43592kb
input:
16 5 157021390 252497011 468873864 892465002 392136945 867902344 634574021 416807938 771790989 545264217 666014055 30318904 997001481 92030626 658131204 234369349 43307846 497204529 460391395 44581806 107577365 871932521 470029953 149175762 27325626 819200707 411063821 891562850 191893364 790514504 ...
output:
85280541
result:
ok 1 number(s): "85280541"
Test #6:
score: 0
Accepted
time: 3ms
memory: 43552kb
input:
16 1 905581565 803883371 222387735 113243327 962846914 170270764 908119897 643672711 951948550 443390704 345262472 285268917 716661556 492805236 516049466 646586240 717205802 712046214 204789431 592343665 608834746 958679690 85385338 156417764 101326890 777140727 427162035 294565259 28802739 8285324...
output:
17305742
result:
ok 1 number(s): "17305742"
Test #7:
score: 0
Accepted
time: 31ms
memory: 59172kb
input:
16 1889 291592828 902768692 198687222 265645285 254788066 848949408 683064381 678157787 474168528 862103895 415053306 909831425 935938735 21752343 43155905 228914827 364068446 273045932 507519451 796711939 166902447 72879739 611394755 843648198 3964648 56114938 95672745 864116356 549815108 867090999...
output:
1000245565
result:
ok 1 number(s): "1000245565"
Test #8:
score: 0
Accepted
time: 15ms
memory: 56072kb
input:
16 1538 462407755 549251277 397837861 275994586 415476819 756356324 34904944 520197632 412094442 727727503 875452091 754767133 581156730 826224521 313192343 54965862 57572067 254043810 294905166 657621093 929264117 362049084 974381916 63383415 506826999 577114576 490305008 452699725 907812132 906157...
output:
141964726
result:
ok 1 number(s): "141964726"
Test #9:
score: 0
Accepted
time: 19ms
memory: 53584kb
input:
16 1234 344382827 816941878 819839652 144225696 371171347 966266104 884665589 169825013 765791827 40228758 652684236 893817865 725991829 758836428 252384190 124837650 871491255 654941544 640590098 175202200 748370570 752347597 100539461 38637304 762795606 419148404 537316998 134122726 29051987 94573...
output:
19530996
result:
ok 1 number(s): "19530996"
Test #10:
score: 0
Accepted
time: 20ms
memory: 60016kb
input:
16 1999 12949977 632196974 390885234 944145973 121838884 405002460 237547721 700781753 461518861 947091309 820524334 253274565 296734976 893264350 934506037 438497421 658309595 402128381 470963494 423098778 698061936 170098990 137416574 542917450 696307461 580493544 236741484 982061646 908169428 985...
output:
162533703
result:
ok 1 number(s): "162533703"
Subtask #2:
score: 15
Accepted
Dependency #1:
100%
Accepted
Test #11:
score: 15
Accepted
time: 0ms
memory: 43612kb
input:
16 15 314601745 720760464 91785724 114888585 26836821 376536402 313090153 826230415 346734724 333924807 863460032 368340108 245372320 36392298 788713548 515760462 298875827 24627338 31898175 284907313 548032583 57534741 75385967 913412369 336300896 498149570 737179693 974479561 859718707 297256598 3...
output:
407303714
result:
ok 1 number(s): "407303714"
Test #12:
score: 0
Accepted
time: 810ms
memory: 167228kb
input:
32 10000 761517608 533611175 252111851 40247028 679296910 479128630 648063750 922719043 15905318 450067426 673017960 429004044 149250097 455699505 781122302 247622532 8960746 139853274 715899414 341830718 10123661 958972771 98773785 523065821 813633478 25481882 318862349 244623710 119270736 59145995...
output:
807722853
result:
ok 1 number(s): "807722853"
Test #13:
score: 0
Accepted
time: 121ms
memory: 60336kb
input:
32 1357 321954818 61258364 443769502 627726057 577984222 31067437 471030721 456785680 899823567 428940817 921238219 804535628 668867012 78750695 982200891 387928209 411806976 435420237 876420011 945079305 839002423 438946076 548079677 475785723 548284753 712759055 517364800 735798756 948763903 81555...
output:
512286475
result:
ok 1 number(s): "512286475"
Test #14:
score: 0
Accepted
time: 76ms
memory: 56352kb
input:
32 1024 934392183 278139969 946579473 404491033 120629005 736209902 839111219 891890038 147168834 726438981 379448297 349343648 888543489 398955818 91414843 460378381 720916808 485962846 92217516 88982970 894439810 677159472 350046012 746702922 908587590 702246537 685838472 411925085 380074941 68975...
output:
337041603
result:
ok 1 number(s): "337041603"
Test #15:
score: 0
Accepted
time: 0ms
memory: 43824kb
input:
32 8 837464609 53515561 24494092 954419559 538819329 215817794 44847447 557152755 311569172 386498461 978050662 953219718 194456091 857047823 966804131 200271001 662278544 873214841 562896362 46085582 976480847 935118668 490627953 405249905 90676824 444770133 132087962 554258181 870642467 293836206 ...
output:
386491936
result:
ok 1 number(s): "386491936"
Test #16:
score: 0
Accepted
time: 364ms
memory: 97212kb
input:
32 4329 574037069 402057855 471584436 536257468 210791614 335509873 350594515 331998672 619093586 234310158 72138003 640585660 992343322 649961161 435859755 715691054 54901302 186990850 897062441 60958965 397463946 94834577 114023959 124090510 486344869 100418631 317644038 885906296 414631710 391332...
output:
425277770
result:
ok 1 number(s): "425277770"
Test #17:
score: 0
Accepted
time: 451ms
memory: 112048kb
input:
32 5524 730589344 194589124 525976166 64781638 879967066 492669642 53399017 620041854 368209111 251911426 86983444 514701073 959368417 29776594 495435365 25651998 315331723 488137423 120545591 185405324 348174064 360725983 37633884 719538793 105796816 12328479 874514161 464366183 860724464 139507398...
output:
623220909
result:
ok 1 number(s): "623220909"
Test #18:
score: 0
Accepted
time: 507ms
memory: 121060kb
input:
32 6257 880226659 330483877 423871717 175591073 127434348 611932518 366082571 563944372 477260589 992476913 802786709 328672404 193010567 661448005 520335137 82252515 944511007 58280839 388765258 670185858 885749417 709317639 620145777 529001942 892659121 546946701 99505158 979528505 595220956 34078...
output:
128478743
result:
ok 1 number(s): "128478743"
Test #19:
score: 0
Accepted
time: 705ms
memory: 151712kb
input:
32 8735 245435032 953640748 241783478 331441343 87510154 136596437 138578112 967064517 314673925 833034581 212111516 834025854 882925777 582922306 314475903 638063273 171513018 434981897 367101943 378334119 3056692 809430030 4804474 70065939 593225082 236099112 574535154 887825463 386722056 88252308...
output:
405695280
result:
ok 1 number(s): "405695280"
Test #20:
score: 0
Accepted
time: 822ms
memory: 167156kb
input:
32 9999 53543452 138507371 910144777 42784030 948244479 58617879 66647526 302774961 733742236 400462082 844467039 406358748 119257486 496264675 263552002 80384519 286161937 524071888 460654447 2670531 971129382 108374548 371716781 826606146 332228173 362583611 352144250 932076012 344642595 435600511...
output:
800761072
result:
ok 1 number(s): "800761072"
Subtask #3:
score: 0
Runtime Error
Test #21:
score: 0
Runtime Error
input:
16 20000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 0 3 2 5 4 7 6 9 8 11 10 13 12 15 14 2 3 0 1 6 7 4 5 10 11 8 9 14 15 12 13 3 2 1 0 7 6 5 4 11 10 9 8 15 14 13 12 4 5 6 7 0 1 2 3 12 13 14 15 8 9 10 11 5 4 7 6 1 0 3 2 13 12 15 14 9 8 11 10 6 7 4 5 2 3 0 1 14 15 12 13 10 11 8 9 7 6 5 4 3 2 1 0 15 14 13 ...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%