QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#755903#7866. TeleportationasaltfishTL 3ms4192kbC++231.9kb2024-11-16 18:20:532024-11-16 18:20:54

Judging History

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

  • [2024-11-16 18:20:54]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:4192kb
  • [2024-11-16 18:20:53]
  • 提交

answer

//#include <iostream>
//#include <string.h>
//
//using namespace std;
//#define ll long long
//#define endl '\n'
//
//const int mod = 100003;
//
//
//ll lg[21][21][21];
//ll w(ll a, ll b, ll c)
//{
//    if (a <= 0 || b <= 0 || c <= 0)
//        return 1;
//    if (a > 20 || b > 20 || c > 20)
//        return w(20, 20, 20);
//    if (lg[a][b][c])
//        return lg[a][b][c];
//    if (a < b && b < c)
//        return w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c);
//    return w(a - 1, b, c) + w(a - 1, b - 1, c) + w(a - 1, b, c - 1) - w(a - 1, b - 1, c - 1);
//}
//
//ll a, b, c;
//
//int main()
//{
//    ios::sync_with_stdio(false);
//    cin.tie(nullptr);
//    while (cin >> a >> b >> c)
//    {
//        if (a == -1 && b == -1 && c == -1)
//            break;
//        memset(lg, 0, sizeof lg);
//        printf("w(%lld,%lld,%lld) = %lld\n", a, b, c, w(a, b, c));
//    }
//}


#include <iostream>
#include <string.h>
#include<queue>
using namespace std;
#define ll long long
#define endl '\n'

int edge[100005], n, x, vis[100005];
struct node
{
    int step, now, to;
};
void bfs(int tar)
{
    fill(vis, vis + n, 1e9);
    queue<node>q;
    q.emplace(0, 0, edge[0]);
    vis[0] = 0;
    while (q.size())
    {
        auto [step, now, to] = q.front();
        q.pop();
        if (vis[to] >= step + 1)
        {
            q.emplace(step + 1, to, edge[to]);
            vis[to] = step + 1;
        }
        if (vis[(to + 1) % n] >= step + 2)
        {
            q.emplace(step + 1, now, (to + 1) % n);
            vis[(to + 1) % n] = step + 2;
        }
    }
    cout << vis[tar];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n >> x;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        edge[i] = (i + a) % n;
    }
    bfs(x);
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

input:

4 3
0 1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

4 3
0 0 0 0

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

4 3
2 2 2 2

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

2 1
0 0

output:

2

result:

ok 1 number(s): "2"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

2 1
1 1

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3628kb

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: 2ms
memory: 4080kb

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: 1ms
memory: 3588kb

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: 1ms
memory: 3760kb

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: 3ms
memory: 4192kb

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: -100
Time Limit Exceeded

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:


result: