QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#426481 | #8538. Infinite Adventure | RedreamMer | 100 ✓ | 817ms | 449332kb | C++17 | 2.6kb | 2024-05-31 12:38:07 | 2024-05-31 12:38:08 |
Judging History
answer
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <cstdio>
#include <random>
#include <limits>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
#define PB emplace_back
#define int long long
#define ll long long
#define vi vector<int>
#define siz(a) ((int) ((a).size()))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
void print(vi n) { rep(i, 0, siz(n) - 1) cerr << n[i] << " \n"[i == siz(n) - 1]; }
const int N = 1e5, inf = 2e18;
int a, b, t[N + 5];
vi s[N + 5], f[61][N + 5], g[61][N + 5];
void solve(int n, int m, int k) {
m %= t[n];
if(f[k][n][m]) return;
// cout << k << ' ' << n << ' ' << m << ' ' << t[n] << endl;
if(k) {
solve(n, m, k - 1);
if(t[f[k - 1][n][m]] == t[n]) {
int o = (m + g[k - 1][n][m]) % t[n];
solve(f[k - 1][n][m], o, k - 1);
f[k][n][m] = f[k - 1][f[k - 1][n][m]][o];
g[k][n][m] = min(inf, g[k - 1][n][m] + g[k - 1][f[k - 1][n][m]][o]);
}
else f[k][n][m] = f[k - 1][n][m], g[k][n][m] = g[k - 1][n][m];
return;
}
int v = s[n][m], now = 1;
while(1) {
if(t[v] >= t[n]) {
f[0][n][m] = v, g[0][n][m] = now;
break;
}
else {
// cout << "QWQ" << endl;
solve(v, (m + now) % t[v], 60);
int vv = f[60][v][(m + now) % t[v]];
if(t[vv] > t[v]) now += g[60][v][(m + now) % t[v]], v = vv;
else {
f[0][n][m] = s[n][m], g[0][n][m] = 1;
break;
}
}
}
// cerr << k << ' ' << n << ' ' << m << ' ' << v << ' ' << now << endl;
}
signed main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> a >> b;
rep(i, 1, a) {
cin >> t[i], s[i].resize(t[i]);
rep(j, 0, 60) f[j][i].resize(t[i]), g[j][i].resize(t[i]);
}
rep(i, 1, a) rep(j, 0, t[i] - 1) cin >> s[i][j];
rep(i, 1, a) rep(j, 0, t[i] - 1) rep(k, 0, 60) solve(i, j, k);
int x, y, z;
rep(i, 1, b) {
cin >> x >> y >> z;
while(z) {
if(z < g[0][x][y % t[x]]) {
x = s[x][y % t[x]], ++y, --z;
continue;
}
per(i, 60, 0) if(z >= g[i][x][y % t[x]]) {
int v = f[i][x][y % t[x]];
z -= g[i][x][y % t[x]];
y += g[i][x][y % t[x]];
x = v;
}
// cerr << i << ' ' << z << endl;
}
cout << x << '\n';
}
return cerr << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl, 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5.55556
Accepted
time: 36ms
memory: 292316kb
input:
5 4 1 2 1 2 8 2 3 4 4 2 3 5 5 5 5 5 1 5 5 2 4 3 3 3 6 5 3 2 5 3 7
output:
2 2 5 4
result:
ok 4 lines
Test #2:
score: 5.55556
Accepted
time: 39ms
memory: 292496kb
input:
5 5 1 2 1 2 8 2 3 4 4 2 3 5 5 5 5 5 1 5 5 2 4 3 3 2 6 5 3 2 5 3 7 5 3 1000000000000000000
output:
2 3 5 4 2
result:
ok 5 lines
Test #3:
score: 5.55556
Accepted
time: 301ms
memory: 363588kb
input:
8191 50000 4096 2048 2048 1024 1024 1024 1024 512 512 512 512 512 512 512 512 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 128 64 64 64 64 64 64 64 64 64 64 ...
output:
6024 4871 6829 2843 2704 7750 4426 663 1979 6669 444 637 5654 2976 2555 639 934 3493 6138 645 4601 6468 1607 1616 4886 3193 3082 4508 4355 5688 5070 1344 7578 8056 2441 1050 5628 2887 7100 5425 2944 6950 6251 1616 5118 6390 8075 1657 1670 6996 4616 5551 7771 8033 4349 1119 534 414 2817 3343 2739 512...
result:
ok 50000 lines
Test #4:
score: 5.55556
Accepted
time: 76ms
memory: 294924kb
input:
342 49996 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 4 1 1 1 1 1 1 1 16 1 1 1 16 1 1 1 1 1 1 1 1 4 1 1 4 1 1 1 1 1 4 4 1 1 1 4 1 4 4 1 4 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 4 1 1 1 1 1 1 4 1 1 4 1 4 1 1 1 1 1 1 1 1 1 16 1 1 1 1 1 1 4 1 1 1 4 1 1 1 4 16 4 1 1 1 1 1 1 4 1 1 1 1 1 1 16 4 4 4 1 1 1 1 4 1 4 1 1 1 ...
output:
183 9 332 46 332 332 332 9 332 121 200 155 46 332 200 332 200 332 183 200 183 155 9 9 121 9 46 46 200 183 183 200 332 183 121 183 200 9 200 46 183 46 46 9 46 46 183 183 155 332 332 46 121 200 332 46 332 121 46 183 46 183 46 155 9 183 46 9 332 46 46 46 9 183 155 183 121 200 200 183 332 121 200 332 20...
result:
ok 49996 lines
Test #5:
score: 5.55556
Accepted
time: 103ms
memory: 294920kb
input:
342 49991 1 4 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 4 1 1 64 1 4 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 1 4 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 16 1 1 1 4 4 1 1 1 16 1 1 1 1 64 1 1 1 4 1 1 1 1 1 1 1 1 1 4 1 1 4 1 1 1 1 1 4 1 4 1 1 1 1 1 1 1 1 1 4 16 16 16 1 256 1 1 1 1 1 4 4 4 1 1 1 4 1 4 4 1 1 4 1 1 ...
output:
154 337 287 260 174 337 99 110 40 101 251 273 142 247 171 107 177 231 7 325 174 280 257 208 330 189 273 287 253 79 142 240 208 257 101 28 70 62 110 181 168 280 303 187 193 291 101 270 62 166 66 174 135 297 306 152 143 130 187 11 66 179 243 270 249 7 240 306 199 314 147 273 28 154 55 287 146 273 270 ...
result:
ok 49991 lines
Test #6:
score: 5.55556
Accepted
time: 157ms
memory: 307648kb
input:
2359 49991 1 1 2 2 2 2 1 1 2 4 1 2 1 1 1 2 1 4 2 2 1 1 1 4 1 1 1 1 2 1 1 8 1 2 2 1 1 4 2 1 1 4 2 2 4 8 1 4 1 2 4 8 1 2 4 1 2 1 1 4 4 1 2 1 2 8 1 1 1 4 1 2 4 1 4 1 1 1 2 1 1 1 4 1 4 1 1 1 2 2 1 2 2 1 2 1 2 2 4 1 1 1 4 1 2 1 1 4 1 1 2 1 4 1 2 4 1 4 1 8 1 1 4 8 2 4 2 1 1 4 1 4 1 4 1 4 2 2 1 1 8 8 1 1 2...
output:
536 1887 1711 1552 1780 2221 1359 1896 1676 112 104 979 2057 635 616 1434 1164 189 2230 1741 480 1302 151 225 1896 104 1896 1164 1247 2145 1831 874 328 715 874 1341 1537 752 635 2117 752 43 2143 740 2357 189 2002 235 2230 1010 1247 974 1856 1718 512 1552 1537 1994 752 1291 1134 861 616 1676 2057 252...
result:
ok 49991 lines
Test #7:
score: 5.55556
Accepted
time: 188ms
memory: 307320kb
input:
2292 49996 1 1 8 1 1 1 2 1 2 1 1 1 1 8 1 1 1 1 2 1 4 2 1 1 1 1 2 1 8 8 4 1 4 1 1 2 1 2 4 1 1 2 2 2 1 4 4 4 2 1 1 1 2 1 1 1 2 1 1 2 2 1 1 1 1 4 8 1 8 1 1 1 1 1 1 4 4 1 8 1 1 1 2 4 1 2 4 2 4 2 4 4 2 2 1 1 1 2 1 1 2 1 8 1 1 1 1 1 1 1 1 4 2 2 2 4 1 1 4 1 2 1 4 4 1 2 2 2 1 2 2 2 1 1 1 1 2 1 1 4 1 1 2 1 2...
output:
948 2024 1 512 818 1533 306 988 1026 847 244 1920 1130 76 1879 100 1445 1513 1720 868 1479 907 2170 465 1380 168 1657 513 2003 1055 1446 635 1216 273 140 1245 2246 1488 2197 1657 864 1297 1449 367 1320 1067 1734 200 1777 210 640 970 1762 230 2124 1645 1706 1126 1019 263 358 465 2285 2185 1471 804 20...
result:
ok 49996 lines
Test #8:
score: 5.55556
Accepted
time: 179ms
memory: 307536kb
input:
2312 49992 4 2 1 1 4 1 1 1 1 4 2 2 2 1 1 1 1 1 1 4 1 4 1 1 8 2 2 8 4 1 8 2 1 2 1 1 2 1 1 1 2 2 4 1 1 1 1 4 1 2 2 2 1 2 4 1 1 4 1 1 1 1 1 4 1 2 2 4 1 1 2 1 1 8 1 2 1 1 1 2 2 2 1 1 1 4 1 1 2 1 1 1 1 1 2 1 1 2 2 1 4 4 1 1 4 1 4 1 4 2 2 1 4 1 2 2 1 1 2 2 2 2 2 1 2 2 1 2 1 4 1 2 1 2 2 1 1 1 1 4 1 1 2 1 1...
output:
94 1129 1925 1506 2139 607 325 799 1115 2220 37 200 2106 718 1491 2163 280 1605 376 2163 409 990 2109 147 1361 1388 531 926 917 1405 877 164 850 181 1417 905 337 1397 651 1671 1304 898 1080 478 650 1364 2082 292 729 1014 686 572 1098 1983 600 2132 2145 115 98 7 805 1256 1590 85 1605 220 1023 138 993...
result:
ok 49992 lines
Test #9:
score: 5.55556
Accepted
time: 529ms
memory: 403164kb
input:
16386 49994 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 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:
6023 11681 12823 9852 9349 217 14678 9802 12471 8273 13520 443 2232 77 5039 10234 13587 5336 15949 7044 11003 11112 6828 7826 15021 5732 15049 11176 65 47 15440 15147 11346 9786 13637 16187 6126 8584 8677 13794 16258 337 12822 8380 6729 11668 3759 6214 15885 7224 15472 2899 1157 720 13094 10091 1302...
result:
ok 49994 lines
Test #10:
score: 5.55556
Accepted
time: 519ms
memory: 403148kb
input:
16386 49995 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 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:
7961 13002 16226 15340 9494 7876 3408 15786 10922 4714 6780 9250 15779 9514 10479 13835 13287 2703 14855 1870 14534 6645 4482 10361 12389 9576 14013 8030 5151 6302 9095 11805 8565 4459 3296 2790 12662 2367 11725 2735 5383 7001 8847 12724 9354 11432 9990 5746 11053 8753 2644 15628 15374 10557 15992 3...
result:
ok 49995 lines
Test #11:
score: 5.55556
Accepted
time: 603ms
memory: 436296kb
input:
19859 49993 4 1 1 1 2 1 1 2 1 1 1 2 16 2 1 2 1 1 2 2 1 1 1 2 4 4 1 2 2 4 1 1 1 2 1 1 1 1 2 2 2 1 8 1 1 4 1 4 2 1 4 1 2 1 4 1 1 8 2 4 1 2 2 4 1 8 1 1 1 1 2 1 1 1 1 32 2 4 2 4 1 2 4 2 2 4 1 4 2 1 16 1 2 4 1 1 1 2 1 2 1 2 1 1 2 1 4 2 1 4 1 8 4 1 2 1 4 1 1 1 1 1 8 2 1 2 4 2 2 1 1 1 1 2 2 1 1 16 1 32 2 4...
output:
14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 14409 ...
result:
ok 49993 lines
Test #12:
score: 5.55556
Accepted
time: 586ms
memory: 436592kb
input:
19960 49997 2 2 2 16 4 4 2 1 2 1 1 1 1 1 4 1 1 1 8 1 32 1 1 1 1 1 1 2 1 2 1 1 1 1 32 1 1 8 2 2 1 4 2 1 2 2 1 1 8 1 1 1 2 2 4 1 2 4 1 4 2 2 1 1 1 1 16 1 4 2 8 16 1 1 1 4 1 4 1 1 16 1 4 1 8 4 2 1 2 2 4 2 1 2 4 1 2 8 2 1 8 1 2 2 1 2 2 1 1 1 1 2 4 4 4 1 1 2 2 4 2 2 1 1 1 4 1 1 1 2 1 1 2 2 4 1 1 1 1 1 1 ...
output:
18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 18257 ...
result:
ok 49997 lines
Test #13:
score: 5.55556
Accepted
time: 739ms
memory: 436488kb
input:
19898 49993 8 8 1 1 1 2 2 2 1 1 16 2 4 4 1 4 2 1 1 2 1 8 2 2 1 4 2 1 32 1 1 1 8 1 1 1 2 1 1 4 1 16 4 2 1 1 2 2 1 2 1 4 2 1 1 4 2 1 1 16 1 1 4 1 1 1 4 2 8 16 2 2 2 1 4 1 1 2 1 1 2 1 1 2 1 1 2 1 1 1 1 16 4 2 1 1 8 1 1 8 1 4 8 1 1 4 4 1 4 1 2 4 4 8 2 1 1 1 8 4 1 1 4 1 16 2 1 2 4 8 2 1 1 1 1 2 2 1 2 2 1...
output:
18432 18432 909 18432 18432 1945 18432 5036 4618 5345 18432 18432 18432 5760 18432 4783 957 2286 18432 2571 18432 3578 4018 19859 4950 18432 4656 5334 18432 2648 5000 19315 4338 18432 3255 1679 18432 3080 18432 1024 5133 1467 1267 4077 18432 4644 5292 18432 18432 1042 6083 5405 18432 2124 5817 18432...
result:
ok 49993 lines
Test #14:
score: 5.55556
Accepted
time: 618ms
memory: 436944kb
input:
20050 49995 4 4 2 1 2 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 2 1 2 1 1 8 1 1 2 2 2 1 1 8 1 4 2 2 8 1 2 1 2 4 2 1 1 1 1 2 2 1 2 1 1 1 1 1 2 1 16 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 1 1 32 16 2 1 16 2 2 1 4 2 8 1 1 16 8 1 2 4 1 1 2 2 2 1 2 1 2 1 1 4 1 1 2 1 1 2 1 1 1 4 4 1 2 1 1 1 1 1 2 2 1 1 1 2 2 1 2 1 1 4 16 2 ...
output:
10008 3567 12414 3567 5791 4085 8960 11881 19773 12248 2100 6842 18766 10581 8960 18961 11079 11825 16669 7278 8450 19442 6041 15186 1578 16771 8707 17705 10580 5316 8899 17451 14988 6298 6216 4302 17477 6802 2188 568 656 12700 19985 6877 1801 8607 15186 6491 10649 6533 16531 18182 9482 16598 1308 6...
result:
ok 49995 lines
Test #15:
score: 5.55556
Accepted
time: 738ms
memory: 448600kb
input:
21377 49995 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 8 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 1 2 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 ...
output:
13591 1543 11272 17223 17344 10407 19780 11668 13177 3064 6240 21141 15860 11625 13828 11082 1730 15745 8071 13446 18100 14094 13667 13392 9123 8597 13702 21323 8092 12517 17222 14822 14978 9410 3663 20426 16828 1689 16355 215 13243 9355 9696 11843 14755 15138 1333 3049 9559 14993 10085 17030 8021 2...
result:
ok 49995 lines
Test #16:
score: 5.55556
Accepted
time: 807ms
memory: 449332kb
input:
21609 49996 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 1 1 1 1 4 1 1 1 4 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 2 8 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 4 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
5790 11643 6322 16909 5889 14038 14373 5889 1645 4813 21121 6497 11648 1624 19532 1002 4892 1945 12330 12056 4777 19247 14530 3929 19646 12007 19653 11487 5433 19633 7442 10186 6325 10544 4198 6902 2284 14425 14275 1676 12084 12177 16468 18075 19911 9997 19131 21159 14459 855 769 19964 1910 15242 30...
result:
ok 49996 lines
Test #17:
score: 5.55556
Accepted
time: 817ms
memory: 448636kb
input:
21384 50000 1 1 1 8 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 32 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 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 4 1 1 1 1 1 2 1 1 1 1 1 1 2 4 8 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 2 1 2 1 4 1 1 1 1 1 ...
output:
18285 13707 15017 21239 3294 3680 5100 13746 9772 10064 4497 12784 19541 13721 18244 18708 1959 6765 14910 16196 9347 10657 19302 6994 6765 20863 6792 10919 5100 7386 6819 14518 3768 3837 12168 3807 2364 17545 20808 10527 5100 21193 1885 10809 19807 7713 7130 15179 13317 14308 11955 10765 9919 14341...
result:
ok 50000 lines
Test #18:
score: 5.55556
Accepted
time: 795ms
memory: 448492kb
input:
21120 49998 1 1 1 1 1 1 1 1 2 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 16 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 2 2 1 1 2 1 1 2 8 1 1 1 1 1 1 1 1 16 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 2 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 2 2 1 1 1 ...
output:
18536 5817 16641 4164 5210 3321 3736 13264 17500 4141 17503 19438 19489 17534 19433 17265 5659 16760 8931 4274 19502 9842 18770 16780 13180 19429 4141 5771 4395 686 668 15270 5190 3761 3675 8048 19310 13209 19426 20307 20100 15032 5652 18738 1241 16345 266 5487 17781 9474 17394 4672 19912 16079 1550...
result:
ok 49998 lines