QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#756439 | #7866. Teleportation | Asda111 | AC ✓ | 26ms | 12428kb | C++17 | 1.8kb | 2024-11-16 20:29:20 | 2024-11-16 20:29:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using PII = pair<int,int>;
const int N = 100005;
int n, m;
int a[N];
int h[N * 2], nxt[N * 5], to[N * 5], w[N * 5], cnt = 1;
void ad(int a, int b, int c)
{
to[cnt] = b;
nxt[cnt] = h[a];
w[cnt] = c;
h[a] = cnt++;
}
bool vis[N * 3];
int d[N * 3];
priority_queue< PII, vector<PII>, greater< PII >> q;
void dijkstra(int s)
{
d[s] = 0;
q.push({0, s});
while (!q.empty())
{
int u = q.top().second;
q.pop();
if (vis[u])
continue;
vis[u] = 1;
for (int i = h[u]; ~i; i = nxt[i])
{
int v = to[i], wd = w[i];
if (d[v] > d[u] + wd)
{
d[v] = d[u] + wd;
q.push({d[v], v});
}
}
}
}
// int spfa(int s)
// {
// d[s] = 0;
// vis[s] = 1;
// q.push(s);
// while (!q.empty())
// {
// int x = q.front();
// q.pop();
// vis[x] = 0;
// for (int i = h[x]; ~i; i = nxt[i])
// {
// int y = to[i];
// int z = w[i];
// if (d[y] > d[x] + z)
// {
// d[y] = d[x] + z;
// if (!vis[y])
// q.push(y), vis[y] = 1;
// }
// }
// }
// return d[m];
// }
int main()
{
memset(h, -1, sizeof(h));
memset(d, 0x3f, sizeof(d));
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
{
scanf("%d", a + i);
}
for (int i = 0; i < n; i++)
{
ad(i + n, i, 0);
//ad(i, i + n, i == 0);
ad(i, (i + a[i]) % n +n, 1);
ad(i + n, (i + 1) % n + n, 1);
}
dijkstra(0);
cout << d[m];
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 11072kb
input:
4 3 0 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 11820kb
input:
4 3 0 0 0 0
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 11148kb
input:
4 3 2 2 2 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 1ms
memory: 11548kb
input:
2 1 0 0
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 11476kb
input:
2 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 2ms
memory: 11808kb
input:
300 25 182 9 13 211 258 132 27 42 218 200 271 258 164 121 8 84 29 195 141 290 110 0 272 93 142 134 140 32 232 99 162 199 297 287 212 29 182 53 61 98 116 282 75 245 230 165 22 4 179 89 274 231 46 299 248 208 200 285 221 50 221 199 294 241 195 138 22 204 113 100 132 276 158 146 238 178 100 94 131 157 ...
output:
10
result:
ok 1 number(s): "10"
Test #7:
score: 0
Accepted
time: 0ms
memory: 11428kb
input:
300 49 5 0 5 6 8 1 2 6 8 8 0 7 0 0 2 0 7 3 6 0 7 2 6 4 3 9 9 6 5 0 9 1 4 1 5 2 5 5 2 5 5 5 9 9 2 7 0 0 6 6 9 7 10 3 5 2 6 3 0 8 6 4 4 9 7 4 8 0 2 4 5 0 6 5 7 0 9 5 1 3 9 2 3 5 8 2 0 1 0 8 2 4 5 1 10 8 8 8 5 3 1 7 6 8 10 1 6 5 8 2 1 1 10 1 5 1 6 1 7 5 3 3 6 8 8 6 2 0 4 9 7 1 8 5 9 5 0 3 1 8 0 0 2 8 0...
output:
14
result:
ok 1 number(s): "14"
Test #8:
score: 0
Accepted
time: 2ms
memory: 11796kb
input:
2000 1535 297 1103 1985 224 645 892 493 1146 258 729 686 230 1509 1197 1970 577 1462 672 1133 737 226 1248 1236 492 473 495 1395 942 641 1010 39 759 625 1684 725 235 327 1217 321 512 675 331 1864 915 1386 713 1559 1475 643 1347 1697 101 1533 1511 1596 1486 776 439 148 460 919 1529 1463 1070 1940 597...
output:
12
result:
ok 1 number(s): "12"
Test #9:
score: 0
Accepted
time: 0ms
memory: 11396kb
input:
10000 8363 435 437 137 171 494 479 76 224 219 348 459 215 351 368 101 323 208 271 149 40 290 281 491 234 1 304 405 106 26 112 89 471 232 237 445 482 215 17 357 26 33 3 185 45 234 426 61 60 5 244 32 88 93 128 19 381 222 187 356 177 259 116 60 268 157 50 293 152 380 38 296 466 425 460 281 168 408 138 ...
output:
30
result:
ok 1 number(s): "30"
Test #10:
score: 0
Accepted
time: 8ms
memory: 11184kb
input:
30000 9089 1388 1944 499 465 901 1627 647 1311 1135 1649 263 898 852 1600 940 33 164 18 110 916 1705 1975 966 1493 336 457 695 1893 1575 2000 1146 1268 1633 1047 1106 1541 681 807 236 596 471 374 954 851 1283 392 1042 624 1244 1593 160 1976 1856 115 1100 743 1874 1580 1775 440 1470 1150 287 1526 109...
output:
17
result:
ok 1 number(s): "17"
Test #11:
score: 0
Accepted
time: 6ms
memory: 12156kb
input:
50000 10744 8 6 9 7 10 8 7 9 7 8 4 6 9 5 4 8 9 3 0 3 6 0 6 0 6 2 1 3 7 10 4 8 7 8 2 7 8 3 0 9 2 10 10 3 0 5 8 3 1 6 3 0 3 8 6 7 8 0 5 3 6 0 4 2 6 3 8 3 0 1 9 0 6 1 5 5 8 3 5 2 7 0 9 0 7 2 5 8 4 9 0 8 2 8 6 0 4 2 6 8 8 8 4 6 9 1 6 6 8 9 8 6 4 9 4 5 2 6 5 5 1 10 1 8 9 5 2 0 2 4 8 5 6 9 10 0 7 8 7 5 9 ...
output:
1845
result:
ok 1 number(s): "1845"
Test #12:
score: 0
Accepted
time: 26ms
memory: 12320kb
input:
100000 80007 23901 71465 9481 98727 78470 22914 2469 5998 53210 25993 3995 11348 30510 56447 17276 78307 18315 42068 38635 63126 26255 63984 57248 58304 64365 17838 28517 18979 95944 36315 6075 69529 96508 6939 6038 56047 41846 82117 41053 49669 95895 45890 74635 90735 75412 27250 87729 68343 66201 ...
output:
16
result:
ok 1 number(s): "16"
Test #13:
score: 0
Accepted
time: 10ms
memory: 12260kb
input:
100000 94250 1 8 8 6 6 0 8 3 0 7 1 4 1 9 9 3 5 5 1 8 5 9 0 1 4 5 8 6 5 6 8 6 7 5 4 5 7 8 5 5 1 5 5 4 6 5 5 7 6 3 3 10 10 2 6 5 6 8 3 4 7 3 2 2 6 10 9 7 3 7 6 7 2 5 8 9 4 5 2 7 1 1 7 9 10 9 3 7 0 3 5 5 7 5 5 0 10 6 1 8 7 2 9 4 1 1 7 1 6 5 3 6 7 5 9 8 6 3 6 0 8 2 0 10 2 0 2 3 0 7 10 3 3 5 6 10 4 10 2 ...
output:
16242
result:
ok 1 number(s): "16242"
Test #14:
score: 0
Accepted
time: 13ms
memory: 11584kb
input:
100000 20417 4 20 16 4 17 18 11 5 7 12 9 6 14 9 9 5 12 2 1 5 3 4 18 14 20 16 12 3 19 10 5 4 3 10 17 9 6 15 2 0 6 16 14 15 10 20 3 2 11 11 19 15 1 20 5 0 1 1 9 2 20 10 0 6 6 15 16 11 13 7 6 16 9 8 1 2 8 7 8 14 10 8 14 15 2 13 18 5 12 4 9 4 20 16 11 17 0 19 5 14 2 10 7 5 8 4 19 2 20 16 10 19 10 18 18 ...
output:
1707
result:
ok 1 number(s): "1707"
Test #15:
score: 0
Accepted
time: 14ms
memory: 11716kb
input:
100000 77449 183 51 136 72 1 114 108 185 35 169 104 25 21 96 181 124 8 92 26 20 94 79 46 99 111 128 110 178 19 146 97 56 67 50 4 186 79 71 150 8 133 170 196 60 75 143 101 188 197 120 138 5 129 85 56 17 127 94 69 141 78 72 21 133 39 47 170 191 83 181 79 9 74 78 65 126 193 167 165 153 128 19 173 183 4...
output:
622
result:
ok 1 number(s): "622"
Test #16:
score: 0
Accepted
time: 18ms
memory: 11968kb
input:
100000 75846 1031 1136 1083 43 1149 1431 1975 1513 1240 350 425 558 1179 32 2237 1575 1501 383 615 700 1437 208 96 1622 1161 2372 1486 2251 2267 1134 1123 2776 2105 2337 1130 882 412 2548 1199 2340 2216 2603 2338 2316 2675 2542 1924 2846 1340 1367 581 2560 1149 2377 1742 1955 2119 1102 588 1416 724 ...
output:
46
result:
ok 1 number(s): "46"
Test #17:
score: 0
Accepted
time: 23ms
memory: 12428kb
input:
100000 29144 1180 13 991 2756 4797 4801 2930 2650 1472 2188 314 1724 200 1556 314 4580 2808 4528 820 1878 1768 917 384 4498 2358 3523 4161 2135 4804 3450 1838 3821 964 2476 1913 1514 805 1416 3330 458 2433 1547 3858 1381 103 704 3996 721 3988 392 1871 654 4829 2670 4480 3400 4588 1433 3763 4892 1868...
output:
18
result:
ok 1 number(s): "18"
Test #18:
score: 0
Accepted
time: 25ms
memory: 12112kb
input:
100000 62039 8812 8350 4373 2152 6155 6457 4157 170 2598 7398 638 8675 3641 2693 8757 334 2846 148 5707 107 6572 7238 2792 2904 2605 202 2496 9806 8620 1704 272 6287 1935 5733 6380 4852 5374 4133 4648 4674 7842 2907 6474 8853 3878 9137 5848 5721 2274 6585 2287 1480 7059 9873 5551 6701 8177 999 842 4...
output:
15
result:
ok 1 number(s): "15"
Test #19:
score: 0
Accepted
time: 4ms
memory: 12108kb
input:
100000 94687 0 0 0 1 0 1 0 1 1 1 0 0 1 1 1 1 0 0 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 1 0 1 1 0 1 1 0 0 1 0 1 1 0 0 1 0 1 1 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 1 0 0 0 0 1 0 0 1 1 1 1 0 1 0 1 0 0 0 0 0 1 1 1 1 1 0 1 1 1 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 1...
output:
94688
result:
ok 1 number(s): "94688"
Test #20:
score: 0
Accepted
time: 8ms
memory: 11788kb
input:
100000 92517 0 1 0 0 0 1 1 1 2 0 2 0 1 2 2 0 0 1 0 1 1 2 2 1 1 0 1 0 1 2 0 0 2 1 2 1 2 1 1 1 2 2 2 1 0 2 1 2 1 2 1 0 1 0 2 1 2 0 1 2 1 0 2 2 1 1 0 1 0 0 0 2 0 1 2 2 2 1 2 0 1 2 1 1 1 2 1 1 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 2 2 2 0 0 0 1 0 1 0 0 2 1 0 2 0 1 2 2 2 2 1 0 0 2 1 1 1 2 2 1 2 1 0 1 1 1 0 0 2 2...
output:
69476
result:
ok 1 number(s): "69476"
Test #21:
score: 0
Accepted
time: 8ms
memory: 11800kb
input:
100000 80101 3 3 1 0 1 3 2 0 0 0 2 2 1 1 1 0 1 2 2 0 1 0 1 0 2 2 3 2 2 2 2 0 1 2 2 1 1 3 1 2 2 1 0 3 3 1 0 0 3 2 2 0 1 0 3 1 0 1 0 1 3 3 3 3 3 3 0 0 0 1 1 3 0 1 3 1 0 3 3 2 1 0 2 2 0 3 1 1 2 1 1 3 1 2 0 0 1 2 2 2 0 1 1 2 2 2 2 2 2 0 2 2 3 0 2 3 0 0 3 2 1 0 2 3 3 0 1 0 0 3 0 1 0 3 1 3 1 2 1 2 1 2 1 1...
output:
44759
result:
ok 1 number(s): "44759"
Test #22:
score: 0
Accepted
time: 7ms
memory: 12204kb
input:
100000 96857 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...
output:
96858
result:
ok 1 number(s): "96858"
Test #23:
score: 0
Accepted
time: 4ms
memory: 11880kb
input:
100000 1 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...
output:
2
result:
ok 1 number(s): "2"
Test #24:
score: 0
Accepted
time: 8ms
memory: 11676kb
input:
100000 1 1 0 0 0 1 0 1 0 1 1 1 0 0 1 1 1 1 0 0 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 1 0 1 0 1 1 0 1 1 0 1 1 0 0 1 0 1 1 0 0 1 0 1 1 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 1 0 0 0 0 1 0 0 1 1 1 1 0 1 0 1 0 0 0 0 0 1 1 1 1 1 0 1 1 1 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 1 0...
output:
1
result:
ok 1 number(s): "1"
Test #25:
score: 0
Accepted
time: 4ms
memory: 12108kb
input:
100000 1 2 0 1 0 0 0 1 1 1 2 0 2 0 1 2 2 0 0 1 0 1 1 2 2 1 1 0 1 0 1 2 0 0 2 1 2 1 2 1 1 1 2 2 2 1 0 2 1 2 1 2 1 0 1 0 2 1 2 0 1 2 1 0 2 2 1 1 0 1 0 0 0 2 0 1 2 2 2 1 2 0 1 2 1 1 1 2 1 1 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 2 2 2 0 0 0 1 0 1 0 0 2 1 0 2 0 1 2 2 2 2 1 0 0 2 1 1 1 2 2 1 2 1 0 1 1 1 0 0 2 2 0...
output:
75114
result:
ok 1 number(s): "75114"
Test #26:
score: 0
Accepted
time: 8ms
memory: 12092kb
input:
100000 1 3 3 3 1 0 1 3 2 0 0 0 2 2 1 1 1 0 1 2 2 0 1 0 1 0 2 2 3 2 2 2 2 0 1 2 2 1 1 3 1 2 2 1 0 3 3 1 0 0 3 2 2 0 1 0 3 1 0 1 0 1 3 3 3 3 3 3 0 0 0 1 1 3 0 1 3 1 0 3 3 2 1 0 2 2 0 3 1 1 2 1 1 3 1 2 0 0 1 2 2 2 0 1 1 2 2 2 2 2 2 0 2 2 3 0 2 3 0 0 3 2 1 0 2 3 3 0 1 0 0 3 0 1 0 3 1 3 1 2 1 2 1 2 1 1 2...
output:
55920
result:
ok 1 number(s): "55920"
Test #27:
score: 0
Accepted
time: 10ms
memory: 12200kb
input:
100000 1 10 1 8 8 6 6 0 8 3 0 7 1 4 1 9 9 3 5 5 1 8 5 9 0 1 4 5 8 6 5 6 8 6 7 5 4 5 7 8 5 5 1 5 5 4 6 5 5 7 6 3 3 10 10 2 6 5 6 8 3 4 7 3 2 2 6 10 9 7 3 7 6 7 2 5 8 9 4 5 2 7 1 1 7 9 10 9 3 7 0 3 5 5 7 5 5 0 10 6 1 8 7 2 9 4 1 1 7 1 6 5 3 6 7 5 9 8 6 3 6 0 8 2 0 10 2 0 2 3 0 7 10 3 3 5 6 10 4 10 2 2...
output:
17206
result:
ok 1 number(s): "17206"
Test #28:
score: 0
Accepted
time: 9ms
memory: 12048kb
input:
100000 1 7 4 20 16 4 17 18 11 5 7 12 9 6 14 9 9 5 12 2 1 5 3 4 18 14 20 16 12 3 19 10 5 4 3 10 17 9 6 15 2 0 6 16 14 15 10 20 3 2 11 11 19 15 1 20 5 0 1 1 9 2 20 10 0 6 6 15 16 11 13 7 6 16 9 8 1 2 8 7 8 14 10 8 14 15 2 13 18 5 12 4 9 4 20 16 11 17 0 19 5 14 2 10 7 5 8 4 19 2 20 16 10 19 10 18 18 18...
output:
8417
result:
ok 1 number(s): "8417"
Test #29:
score: 0
Accepted
time: 18ms
memory: 11660kb
input:
100000 1 168 183 51 136 72 1 114 108 185 35 169 104 25 21 96 181 124 8 92 26 20 94 79 46 99 111 128 110 178 19 146 97 56 67 50 4 186 79 71 150 8 133 170 196 60 75 143 101 188 197 120 138 5 129 85 56 17 127 94 69 141 78 72 21 133 39 47 170 191 83 181 79 9 74 78 65 126 193 167 165 153 128 19 173 183 4...
output:
802
result:
ok 1 number(s): "802"
Test #30:
score: 0
Accepted
time: 18ms
memory: 12316kb
input:
100000 1 1126 1744 1123 676 1947 1771 1087 297 1869 1579 611 1284 1996 196 1508 61 1454 984 1135 1091 554 267 139 705 1730 577 1794 406 520 1592 1972 1999 1262 1036 147 1851 700 1769 772 91 1708 1576 1673 1996 903 1697 1542 1934 707 406 1506 429 62 127 256 252 1345 35 1812 1308 960 905 189 1094 1739...
output:
83
result:
ok 1 number(s): "83"
Test #31:
score: 0
Accepted
time: 17ms
memory: 12396kb
input:
100000 1 4720 19200 10083 15551 13583 5448 2076 14999 23516 26633 8237 3943 20711 23104 25054 29027 18249 14921 22216 16015 18077 20462 3890 17619 1530 9641 21464 25301 14217 29872 24288 25652 3614 11756 16852 3058 4986 22079 14250 18815 27526 17657 24930 27557 17019 2337 917 7104 26322 16070 7636 9...
output:
14
result:
ok 1 number(s): "14"
Test #32:
score: 0
Accepted
time: 26ms
memory: 12348kb
input:
100000 1 13035 23901 71465 9481 98727 78470 22914 2469 5998 53210 25993 3995 11348 30510 56447 17276 78307 18315 42068 38635 63126 26255 63984 57248 58304 64365 17838 28517 18979 95944 36315 6075 69529 96508 6939 6038 56047 41846 82117 41053 49669 95895 45890 74635 90735 75412 27250 87729 68343 6620...
output:
17
result:
ok 1 number(s): "17"
Extra Test:
score: 0
Extra Test Passed