QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#220465 | #5200. BinCoin | suibian_xiaozhao | AC ✓ | 36ms | 8124kb | C++20 | 2.3kb | 2023-10-20 13:55:00 | 2023-10-20 13:55:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using vint = vector<int>;
constexpr int N = 1e3 + 5;
int n, k, p[N], fa[N];
void solve(vector<vint> dat, int ff) {
int m = dat[0].size();
if(m == 1) return fa[dat[0][0]] = ff, void();
vector<vint> pos(k, vint(n + 1));
for(int i = 0; i < k; i++)
for(int j = 0; j < m; j++)
pos[i][dat[i][j]] = j;
auto split = [&](int u, vint arr, vint &a, vint &b) {
bool find = 0;
for(int it : arr)
if(it == u) find = 1;
else if(find) b.push_back(it);
else a.push_back(it);
};
auto check = [&](int u) {
int x = -1, y = -1;
for(int i = 0, sz; i < k; i++) {
sz = pos[i][u];
if(!sz) return false;
if(x == -1 || x == sz) x = sz;
else if(y == -1 || y == sz) y = sz;
else return false;
sz = m - 1 - sz;
if(!sz) return false;
if(x == -1 || x == sz) x = sz;
else if(y == -1 || y == sz) y = sz;
else return false;
}
vint c, d;
for(auto &arr : dat) {
vint a, b;
split(u, arr, a, b);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if(c.empty() || c == a) c = a;
else if(d.empty() || d == a) d = a;
else return false;
if(c.empty() || c == b) c = b;
else if(d.empty() || d == b) d = b;
else return false;
}
return true;
};
for(int id : dat[0]) {
if(!check(id)) continue;
fa[id] = ff;
int beg = dat[0][0];
vector<vint> ldat, rdat;
for(auto arr : dat) {
vint a, b;
split(id, arr, a, b);
if(find(a.begin(), a.end(), beg) == a.end()) a.swap(b);
ldat.push_back(a), rdat.push_back(b);
}
solve(ldat, id), solve(rdat, id);
}
}
int main() {
cin >> n >> k;
vector<vector<int>> dat;
for(int _ = 1; _ <= k; _++) {
vector<int> arr(n, 0);
for(int i = 0; i < n; i++) cin >> arr[i];
dat.push_back(arr);
}
solve(dat, -1);
for(int i = 1; i <= n; i++) cout << fa[i] << (i == n ? '\n' : ' ');
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3460kb
input:
3 50 1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 1 2 3 1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 3 2 1 1 2 3 1 2 3 3 2 1 1 2 3 1 2 3 1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 3 2 1 1 2 3 3 2 1 1 2 3 3 2 1 3 2 1 1 2 3 1 2 3 3 2 1 1 2 3 3 2 1 3 2 1 3 2 1 1 2 3 1 2 3 3 2 1 3...
output:
2 -1 2
result:
ok everything is fine
Test #2:
score: 0
Accepted
time: 1ms
memory: 3504kb
input:
5 60 2 4 3 5 1 1 5 2 4 3 1 5 2 4 3 1 5 2 4 3 1 5 3 4 2 1 5 3 4 2 1 5 3 4 2 1 5 3 4 2 1 5 3 4 2 3 4 2 5 1 2 4 3 5 1 1 5 2 4 3 3 4 2 5 1 2 4 3 5 1 2 4 3 5 1 1 5 2 4 3 3 4 2 5 1 3 4 2 5 1 1 5 2 4 3 2 4 3 5 1 1 5 2 4 3 1 5 3 4 2 3 4 2 5 1 1 5 3 4 2 1 5 2 4 3 1 5 3 4 2 1 5 2 4 3 2 4 3 5 1 2 4 3 5 1 2 4 3...
output:
5 4 4 5 -1
result:
ok everything is fine
Test #3:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
11 73 11 1 7 8 5 6 10 3 9 4 2 5 6 10 8 7 1 11 3 9 4 2 9 3 11 1 7 8 5 6 10 4 2 2 4 11 1 7 8 5 6 10 3 9 9 3 7 1 11 8 10 6 5 4 2 2 4 10 6 5 8 7 1 11 3 9 9 3 7 1 11 8 5 6 10 4 2 11 1 7 8 10 6 5 3 9 4 2 9 3 10 6 5 8 7 1 11 4 2 2 4 5 6 10 8 11 1 7 3 9 2 4 11 1 7 8 10 6 5 3 9 2 4 10 6 5 8 11 1 7 3 9 9 3 10...
output:
8 4 4 -1 6 8 1 3 3 6 1
result:
ok everything is fine
Test #4:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
21 81 9 18 14 13 3 4 7 10 2 21 15 16 5 19 20 12 11 1 17 8 6 14 13 7 4 3 10 2 18 9 21 20 12 6 8 11 1 17 19 15 16 5 2 10 14 13 3 4 7 18 9 21 17 1 11 8 6 12 20 19 5 16 15 2 10 7 4 3 13 14 18 9 21 15 16 5 19 6 8 17 1 11 12 20 15 16 5 19 6 8 17 1 11 12 20 21 9 18 7 4 3 13 14 10 2 5 16 15 19 11 1 17 8 6 1...
output:
8 10 4 13 16 8 4 12 18 18 1 19 10 13 16 19 1 21 21 12 -1
result:
ok everything is fine
Test #5:
score: 0
Accepted
time: 10ms
memory: 5796kb
input:
239 100 31 148 157 39 186 205 65 129 197 152 238 154 9 207 36 92 109 48 230 58 175 135 50 77 11 52 102 21 139 142 210 138 200 83 214 98 209 1 195 17 55 141 146 101 91 174 184 67 27 235 6 198 208 43 236 143 94 29 60 104 120 155 78 40 218 234 147 4 34 38 239 212 112 116 72 59 211 79 82 32 7 170 113 10...
output:
17 23 216 234 232 198 32 97 154 228 52 215 140 145 229 73 83 223 63 3 129 87 172 219 41 185 67 80 40 18 148 170 131 4 15 207 22 40 205 59 151 137 143 134 199 167 189 58 217 135 167 77 153 88 141 18 15 92 100 104 89 30 100 45 205 172 141 14 193 179 16 116 235 90 215 149 58 155 32 81 140 79 235 46 23 ...
result:
ok everything is fine
Test #6:
score: 0
Accepted
time: 31ms
memory: 8012kb
input:
999 50 106 811 585 47 419 592 808 303 290 284 113 865 121 63 312 650 98 599 879 462 426 621 898 889 478 285 353 404 905 842 143 800 109 35 765 385 602 332 549 202 1 503 269 232 983 374 521 639 436 471 801 407 78 259 440 406 937 654 982 675 630 814 20 55 64 137 403 333 354 547 507 344 682 707 859 270...
output:
503 884 747 210 302 29 155 210 489 179 861 991 711 584 579 341 787 186 492 55 672 833 806 315 65 335 647 669 485 696 869 432 411 133 332 195 666 342 429 336 916 155 233 703 803 253 592 180 968 629 870 38 802 25 814 234 297 851 647 151 888 999 865 55 147 597 906 287 149 316 569 532 648 323 429 449 80...
result:
ok everything is fine
Test #7:
score: 0
Accepted
time: 14ms
memory: 5000kb
input:
511 50 381 73 43 356 438 151 173 213 158 239 56 307 486 89 23 427 240 150 153 170 507 259 286 161 465 245 82 510 35 442 455 342 289 85 347 90 15 278 366 228 13 108 406 456 88 22 260 421 222 176 237 258 199 375 12 448 25 232 449 211 440 411 499 70 416 77 181 137 467 225 107 154 328 140 252 378 5 138 ...
output:
235 75 -1 96 138 313 398 295 380 288 243 375 108 445 278 41 388 185 3 360 329 456 89 294 232 192 119 261 439 414 451 16 71 408 442 374 374 193 501 184 464 454 73 18 355 426 472 409 405 359 404 164 141 322 412 239 70 423 57 143 504 451 478 322 457 325 261 135 469 19 393 183 356 191 377 139 137 435 38...
result:
ok everything is fine
Test #8:
score: 0
Accepted
time: 22ms
memory: 5836kb
input:
767 50 446 571 373 460 115 529 599 258 172 437 93 642 545 484 494 390 236 84 268 219 430 399 247 363 559 342 226 225 345 487 371 348 765 707 122 148 661 448 761 718 511 578 65 676 255 510 85 256 383 32 498 449 232 501 757 328 465 504 526 242 186 491 143 177 546 330 539 264 541 704 119 735 35 147 1 7...
output:
71 685 316 670 538 696 130 40 695 215 615 99 608 480 616 674 628 197 727 687 395 488 680 492 474 185 302 357 532 706 74 501 87 235 147 196 536 515 563 335 194 587 203 580 313 495 127 438 451 361 416 209 732 157 582 525 283 155 741 21 644 79 340 414 676 380 672 140 680 464 147 432 443 50 252 580 724 ...
result:
ok everything is fine
Test #9:
score: 0
Accepted
time: 18ms
memory: 5468kb
input:
575 50 44 278 437 263 488 493 471 507 364 392 216 213 59 71 490 252 498 184 559 306 3 83 373 332 10 368 26 155 410 463 265 261 537 528 128 448 400 328 296 500 152 404 173 350 550 474 353 468 135 293 529 567 210 320 25 545 549 151 262 556 194 318 298 248 203 198 104 292 240 171 506 191 540 273 108 10...
output:
89 310 83 287 215 103 564 327 145 332 101 175 412 103 355 -1 544 338 205 57 369 406 96 268 545 155 561 457 80 172 97 412 150 188 473 122 202 571 147 97 36 491 562 278 145 438 22 472 347 235 398 156 394 87 367 394 138 165 213 421 244 496 362 294 132 485 414 406 449 8 392 348 326 367 513 38 465 534 34...
result:
ok everything is fine
Test #10:
score: 0
Accepted
time: 26ms
memory: 7268kb
input:
959 50 56 184 608 639 513 415 202 542 520 132 25 48 840 688 820 899 609 54 863 881 149 147 300 551 368 505 487 858 653 183 807 116 516 144 287 315 17 441 490 787 391 497 531 918 453 823 7 924 872 729 278 530 86 511 871 60 706 400 388 459 867 482 600 136 14 204 879 6 27 802 817 707 399 347 72 252 412...
output:
267 502 321 562 222 204 924 462 193 141 727 632 213 136 306 874 441 910 795 635 23 546 12 876 48 309 6 582 295 774 253 139 485 225 529 393 911 46 577 58 53 148 955 912 673 296 607 881 304 112 376 709 891 48 393 184 127 731 155 823 317 366 594 373 816 570 945 156 266 262 789 252 892 565 159 333 586 8...
result:
ok everything is fine
Test #11:
score: 0
Accepted
time: 35ms
memory: 8124kb
input:
999 50 852 701 763 464 320 451 666 883 748 935 984 369 828 779 254 176 816 166 288 900 796 95 477 881 379 882 920 649 495 104 580 23 612 810 543 109 478 262 860 678 608 506 31 570 560 150 520 364 571 496 940 336 595 97 910 376 614 545 983 121 655 778 180 710 264 110 250 204 433 837 179 143 234 56 42...
output:
249 948 777 722 606 305 199 92 468 244 874 210 657 334 873 9 830 800 874 273 411 482 873 494 611 9 243 850 58 616 570 923 461 297 682 431 708 764 239 338 424 685 444 856 961 616 858 164 977 27 492 128 78 857 456 837 454 388 194 917 685 958 330 245 228 292 637 454 203 165 455 167 587 622 791 633 398 ...
result:
ok everything is fine
Test #12:
score: 0
Accepted
time: 26ms
memory: 7288kb
input:
999 50 563 259 245 827 343 311 809 957 283 472 945 243 113 548 87 231 795 888 881 704 905 437 851 514 777 108 31 103 897 455 427 535 772 701 883 483 831 922 73 394 663 677 99 169 185 759 653 62 33 236 5 687 416 715 278 927 735 407 689 906 212 559 894 513 823 600 990 299 256 910 946 546 301 34 901 38...
output:
926 404 267 100 236 7 789 644 597 756 544 440 399 744 938 890 308 525 41 501 2 937 802 721 401 273 892 398 190 870 108 298 62 600 657 960 18 968 858 923 86 712 328 81 529 847 956 886 86 411 561 580 733 494 48 915 272 734 988 420 473 236 661 998 586 581 733 63 814 573 668 525 922 219 519 825 972 137 ...
result:
ok everything is fine
Test #13:
score: 0
Accepted
time: 32ms
memory: 7996kb
input:
999 50 820 938 801 573 307 387 646 666 832 31 349 937 840 33 348 385 670 788 603 481 76 970 24 620 802 676 995 263 828 428 879 53 760 924 134 479 762 323 778 887 877 295 731 105 326 971 95 465 823 912 671 729 241 719 449 591 93 981 726 683 184 512 147 269 318 347 250 419 663 987 342 88 728 370 23 47...
output:
655 900 223 306 436 207 744 807 543 681 499 289 121 34 501 55 91 54 535 381 958 857 370 970 495 501 225 332 804 815 788 679 31 207 497 886 453 711 400 429 497 190 150 656 612 806 781 351 377 306 894 110 788 585 901 673 365 803 189 373 52 46 16 367 499 530 874 154 454 275 961 804 324 600 144 481 2 53...
result:
ok everything is fine
Test #14:
score: 0
Accepted
time: 25ms
memory: 7240kb
input:
999 50 202 911 448 346 419 773 456 440 787 289 189 384 317 556 423 275 356 482 557 649 737 155 331 182 207 85 996 743 847 642 2 651 598 702 127 89 231 913 952 687 491 130 118 262 237 693 945 509 576 498 809 549 848 949 195 619 405 312 354 657 151 726 12 30 257 304 42 6 677 292 835 686 260 426 9 883 ...
output:
897 642 940 329 696 304 86 650 426 22 754 726 720 656 715 536 671 104 319 772 892 86 973 664 663 417 79 101 564 292 11 933 434 525 694 817 929 184 21 604 621 6 513 813 330 971 378 301 469 822 928 633 599 630 861 698 658 826 455 610 748 784 843 655 889 655 673 160 962 971 676 901 582 662 890 762 517 ...
result:
ok everything is fine
Test #15:
score: 0
Accepted
time: 36ms
memory: 8112kb
input:
999 50 18 930 97 456 844 556 784 651 923 697 942 525 129 762 522 741 52 769 771 327 176 514 15 668 710 811 757 281 250 902 632 323 200 170 721 910 780 825 32 718 705 874 758 518 733 504 961 681 963 187 728 343 191 462 885 737 9 979 861 863 402 928 297 203 437 427 649 828 690 202 711 707 485 866 889 ...
output:
716 331 289 354 696 243 642 914 979 189 642 162 483 715 514 759 241 930 964 833 984 545 616 135 980 646 390 420 459 475 185 718 870 377 552 699 992 450 197 905 270 666 552 179 730 358 645 748 308 908 768 741 336 480 473 791 132 713 383 931 878 550 798 371 168 117 627 29 352 144 492 70 370 451 580 31...
result:
ok everything is fine
Test #16:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
1 100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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:
-1
result:
ok everything is fine