QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#412108#3166. Hopscotchivan_len#WA 3ms4088kbC++201.2kb2024-05-16 08:20:512024-05-16 08:20:51

Judging History

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

  • [2024-05-16 08:20:51]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:4088kb
  • [2024-05-16 08:20:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
#define PB push_back
#define MP make_pair
#define A first
#define B second
#define SZ(x) int(x.size())
#define FR(i, a, b) for (int i = (a); i < (b); ++i)
#define FOR(i, n) FR(i, 0, n)
const int M = 1000000007;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

int n, k;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    vector<vector<vi>> dp(k + 5);
    FOR(i, n) {
        FOR(j, n) {
            int x;
            cin >> x;
            dp[x].PB({i, j, 0});
        }
    }
    int mn = 1 << 30;
    FR(i, 2, k + 1) {
        int s = SZ(dp[i - 1]);
        int t = SZ(dp[i]);

        FOR(j, t) {
            dp[i][j][2] = 1 << 30;
            FOR(l, s) {
                dp[i][j][2] = min(dp[i][j][2], dp[i - 1][l][2] + abs(dp[i - 1][l][0] - dp[i][j][0]) + abs(dp[i - 1][l][1] - dp[i][j][1]));
            }
            if (i == k) mn = min(mn, dp[i][j][2]);
        }
    }
    if (mn == (1 << 30)) cout << "-1\n";
    else cout << mn << '\n';
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

10 5
5 1 3 4 2 4 2 1 2 1
4 5 3 4 1 5 3 1 1 4
4 2 4 1 5 4 5 2 4 1
5 2 1 5 5 3 5 2 3 2
5 5 2 3 2 3 1 5 5 5
3 4 2 4 2 2 4 4 2 3
1 5 1 1 2 5 4 1 5 3
2 2 4 1 2 5 1 4 3 5
5 3 2 1 4 3 5 2 3 1
3 4 2 5 2 5 3 4 4 2

output:

5

result:

ok single line: '5'

Test #2:

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

input:

10 5
5 1 5 4 1 2 2 4 5 2
4 2 1 4 1 1 1 5 2 5
2 2 4 4 4 2 4 5 5 4
2 4 4 5 5 5 2 5 5 2
2 2 4 4 4 5 4 2 4 4
5 2 5 5 4 1 2 4 4 4
4 2 1 2 4 4 1 2 4 5
1 2 1 1 2 4 4 1 4 5
2 1 2 5 5 4 5 2 1 1
1 1 2 4 5 5 5 5 5 5

output:

-1

result:

ok single line: '-1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3872kb

input:

50 10
1 5 5 4 3 6 9 6 4 4 2 8 2 9 4 4 5 2 8 6 9 4 3 9 9 3 4 9 3 9 2 9 8 8 5 9 9 6 9 7 6 7 9 3 7 8 9 3 8 2
6 7 7 3 8 6 3 7 2 3 5 4 8 2 5 3 3 5 3 9 6 2 7 2 2 8 6 7 9 8 5 2 4 9 8 6 8 8 4 3 8 4 8 5 4 5 4 8 3 4
6 8 4 9 2 6 5 9 7 7 2 3 9 8 5 3 2 4 2 3 9 6 7 4 9 4 2 2 2 4 7 4 2 2 8 6 9 3 9 2 2 9 2 9 4 4 8 ...

output:

98

result:

ok single line: '98'

Test #4:

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

input:

50 4
1 3 2 3 3 3 2 2 3 3 2 3 2 2 3 3 3 2 3 3 2 2 3 2 3 3 3 3 3 2 2 2 3 2 2 3 2 2 2 2 2 2 2 3 3 2 3 2 2 3
3 3 2 2 3 3 2 2 3 2 2 3 3 3 3 2 3 3 2 3 2 2 2 3 2 2 3 3 2 3 3 2 3 3 2 3 3 2 3 3 3 2 2 3 2 3 3 3 2 2
3 2 3 3 2 2 2 2 3 3 3 2 2 2 3 3 3 3 2 2 3 2 3 3 3 3 3 2 3 3 2 3 3 3 2 2 2 3 2 2 2 2 3 2 3 2 3 3...

output:

98

result:

ok single line: '98'

Test #5:

score: 0
Accepted
time: 1ms
memory: 4088kb

input:

50 2500
658 2195 1188 410 197 1347 17 1507 1003 329 217 85 1211 1208 2038 2407 662 800 590 796 40 519 697 750 1344 413 280 2360 2406 1838 1235 557 2455 2199 875 912 1511 1615 605 1272 422 88 1127 393 787 216 693 48 1193 399
1153 416 330 983 632 1692 1232 2355 1371 2409 768 1978 1693 1277 2307 684 20...

output:

82607

result:

ok single line: '82607'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3792kb

input:

50 2500
2068 850 1064 560 149 2440 1103 854 2124 192 1367 770 1373 1559 1154 1779 276 609 570 1911 188 670 18 280 1340 1079 2194 51 284 698 1659 378 1039 1107 2442 1613 1467 1860 382 823 1401 1080 1354 979 1537 2265 1432 1018 1983 1055
1462 2028 1648 2121 432 667 582 450 2029 391 101 1022 817 494 19...

output:

82978

result:

ok single line: '82978'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3788kb

input:

50 2500
1591 1542 1784 570 1773 1755 823 2464 1782 984 671 1155 732 616 627 727 860 918 1491 2430 1457 942 1636 1651 1112 85 983 118 1290 1536 832 946 1454 1221 1499 279 2059 791 1304 1260 2478 223 512 89 1580 1396 923 470 478 2046
1412 1219 2331 1970 654 297 1975 1451 2369 2366 383 1646 162 576 150...

output:

83563

result:

ok single line: '83563'

Test #8:

score: 0
Accepted
time: 1ms
memory: 4052kb

input:

50 2500
1063 1204 2248 1008 343 425 290 2179 931 32 789 1352 1704 1599 1052 922 258 1730 356 1070 454 1416 1979 1603 2015 340 1818 2186 894 216 657 1049 786 445 1890 1759 886 438 196 1662 1213 1641 544 1680 1592 1653 42 1258 2074 656
1957 2206 791 1426 1490 480 885 181 349 144 398 1651 968 1337 1154...

output:

82474

result:

ok single line: '82474'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3912kb

input:

50 2500
178 2289 1286 121 114 554 1982 488 767 1478 2009 213 1828 171 1260 839 791 267 2129 758 1664 1728 1676 2243 815 1571 1427 1494 185 1143 1304 2295 590 283 484 941 1167 175 91 1916 814 2045 1563 1347 2300 1323 1376 1526 408 251
2211 1542 1570 1172 1229 1532 1027 2425 1630 83 1016 1462 746 730 ...

output:

82498

result:

ok single line: '82498'

Test #10:

score: 0
Accepted
time: 1ms
memory: 4036kb

input:

50 50
31 6 11 14 10 17 50 45 22 47 23 32 41 35 36 5 4 31 43 11 11 5 13 21 46 45 31 44 32 20 46 39 12 27 34 41 14 7 18 1 32 41 19 12 30 28 1 15 26 50
29 15 10 48 29 3 7 33 28 23 46 46 21 33 49 18 7 37 3 45 27 19 7 38 23 50 16 34 6 28 17 22 31 5 11 9 45 3 11 29 17 42 45 42 34 27 10 17 42 47
50 36 38 1...

output:

171

result:

ok single line: '171'

Test #11:

score: 0
Accepted
time: 1ms
memory: 3752kb

input:

50 50
12 12 25 39 16 19 19 39 34 7 33 2 24 17 28 3 43 43 48 46 1 3 47 42 8 24 45 23 32 10 24 2 45 44 27 43 26 19 15 41 14 11 23 23 6 1 11 3 3 35
46 22 41 47 24 17 44 44 24 6 40 34 25 37 33 47 13 2 26 17 47 19 6 49 4 14 5 3 3 34 35 6 31 30 36 37 24 31 13 7 11 28 44 35 25 36 13 34 22 24
15 48 39 7 34 ...

output:

165

result:

ok single line: '165'

Test #12:

score: 0
Accepted
time: 1ms
memory: 4044kb

input:

50 50
4 30 7 8 2 23 9 40 2 40 25 1 5 3 40 18 30 27 36 36 44 44 5 44 43 49 31 39 3 38 3 2 9 47 35 45 33 27 30 38 32 45 3 41 11 38 17 25 25 35
45 46 15 36 32 13 18 7 39 48 12 5 8 49 36 47 10 25 3 47 30 7 35 15 28 19 18 28 42 28 32 29 36 43 33 3 43 22 12 42 20 23 15 48 38 39 8 8 14 32
9 19 12 47 10 38 ...

output:

158

result:

ok single line: '158'

Test #13:

score: 0
Accepted
time: 1ms
memory: 3804kb

input:

50 50
18 23 21 50 43 1 50 12 50 39 22 43 39 15 18 8 13 7 44 12 23 48 20 50 6 34 20 27 36 23 5 46 16 41 21 29 42 47 29 39 3 10 35 30 9 14 11 1 32 24
32 5 49 23 36 42 36 35 11 18 23 46 21 43 35 13 18 30 24 29 7 7 1 34 19 29 45 39 34 5 50 33 18 10 15 30 22 27 23 17 28 32 13 28 37 1 16 21 46 6
23 42 9 4...

output:

164

result:

ok single line: '164'

Test #14:

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

input:

50 50
48 46 4 12 5 36 28 37 45 11 45 13 35 16 11 33 46 7 45 12 44 1 23 46 28 44 25 12 42 39 35 47 34 36 5 9 39 24 9 23 48 4 15 9 3 40 8 5 29 17
22 42 36 38 49 21 26 31 20 26 30 24 19 2 21 7 31 29 47 48 50 35 48 34 15 44 2 45 34 7 9 1 9 16 40 47 40 40 21 3 47 8 35 1 13 1 45 27 40 1
35 7 31 4 18 24 33...

output:

169

result:

ok single line: '169'

Test #15:

score: 0
Accepted
time: 1ms
memory: 3768kb

input:

50 1000
52 304 227 956 240 789 132 949 678 887 136 435 439 725 114 631 696 141 588 571 107 387 654 713 494 288 531 581 258 182 548 828 145 600 791 548 181 550 504 354 313 141 994 291 719 13 289 522 238 101
167 136 588 601 642 178 16 963 391 724 389 112 845 28 796 641 168 481 561 369 88 41 407 967 62...

output:

-1

result:

ok single line: '-1'

Test #16:

score: 0
Accepted
time: 1ms
memory: 4068kb

input:

50 1000
574 825 901 39 741 62 744 642 782 960 452 740 687 785 589 175 92 892 969 74 840 328 438 301 195 99 814 547 624 427 433 886 266 488 70 260 898 397 749 310 1000 5 243 786 803 802 42 622 918 16
620 541 210 313 725 815 610 265 787 112 455 810 987 810 856 890 648 62 213 151 890 798 504 69 561 886...

output:

-1

result:

ok single line: '-1'

Test #17:

score: 0
Accepted
time: 1ms
memory: 3764kb

input:

50 1000
22 212 586 10 358 224 858 10 716 657 366 915 417 515 816 411 247 760 509 919 886 641 697 189 221 891 96 465 265 821 782 727 180 990 69 679 405 563 569 279 567 374 857 578 625 706 443 918 611 339
268 572 679 250 916 56 755 158 570 288 714 670 265 481 729 203 318 116 693 323 461 928 102 696 76...

output:

-1

result:

ok single line: '-1'

Test #18:

score: 0
Accepted
time: 1ms
memory: 3824kb

input:

50 1000
888 502 33 785 725 302 791 645 790 853 561 87 799 111 584 258 746 982 825 51 634 702 31 316 307 983 133 618 921 437 566 116 931 852 179 268 851 244 704 562 598 764 452 484 154 435 212 354 945 58
83 229 161 302 887 712 877 737 354 118 731 208 779 19 722 31 602 887 368 80 693 837 350 450 425 8...

output:

-1

result:

ok single line: '-1'

Test #19:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

50 1000
695 898 4 396 546 342 260 882 34 602 537 409 117 191 517 262 821 401 44 825 983 295 378 782 465 410 548 250 136 398 644 243 259 327 987 73 752 77 482 640 769 927 481 583 819 422 371 323 498 928
268 381 28 189 481 138 81 6 210 937 115 889 630 895 104 193 67 614 553 323 591 420 143 659 481 864...

output:

-1

result:

ok single line: '-1'

Test #20:

score: -100
Wrong Answer
time: 0ms
memory: 3672kb

input:

1 1
1

output:

-1

result:

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