QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#189704 | #6352. SPPPSPSS. | Nyans | WA | 261ms | 10628kb | C++14 | 1.9kb | 2023-09-27 19:52:17 | 2023-09-27 19:52:18 |
Judging History
answer
#include <cstdio>
#include <vector>
#include <algorithm>
int main() {
int n;
scanf("%d", &n);
std::vector <int> a(n + 1);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
auto solve = [n](std::vector <int> a) {
int mid = (n + 1) / 2;
int l1 = 1, r1 = mid - (mid % 2 == 0);
int l2 = n - mid + 1 + (mid % 2 == 1), r2 = n;
bool flag = 1;
for (int i = 1; i <= r1; ++i) if (a[i] > r1) flag = 0;
for (int i = l2; i <= n; ++i) if (a[i] < l2) flag = 0;
if (flag) {
int l = mid, r = mid + 1;
for (; l && a[l] == l; --l);
for (; r <= n && a[r] == r; ++r);
if (l && l % 2 == 0) ++l;
if ((n - r + 1) % 2 == 1) --r;
return std::max(l, n - r + 1);
}
if (n == 2) return 2;
std::sort(a.begin() + 1, a.begin() + r1 + 1);
std::sort(a.begin() + l2, a.end());
if (n % 2 == 0) {
if (mid % 2) {
--r1, l2 -= 2;
std::sort(a.begin() + l2, a.end());
} else {
++l2, r1 += 2;
std::sort(a.begin() + 1, a.begin() + r1 + 1);
}
++mid;
}
for (; l1 <= r1 && a[l1] == l1; ++l1);
if (l1 > r1) return mid;
for (; a[r2] == r2; --r2);
int L = l1, R = r2;
while (++mid, L <= R) {
if (mid % 2) {
int r = std::min(r2, l2 + mid - L - (r1 - l1 + 1));
while (1)
if (l1 <= r1 && a[l1] == L) ++L, ++l1;
else if (l2 <= r && a[l2] == L) ++L, ++l2;
else break;
} else {
int l = std::max(l1, r1 - mid + (n - R + 1) + (r2 - l2 + 1));
while (1)
if (l2 <= r2 && a[r2] == R) --R, --r2;
else if (l <= r1 && a[r1] == R) --R, --r1;
else break;
}
}
return mid - 1;
};
int ans1 = solve(a);
for (int i = 1; i <= n; ++i) a[i] = n + 1 - a[i];
std::reverse(a.begin() + 1, a.end());
int ans2 = -solve(a);
if (ans1 <= -ans2) {
// printf("%d\n", ans1);
for (int i = 0; i < ans1; ++i) putchar("PS"[i % 2]);
} else {
// printf("%d\n", -ans2);
for (int i = 0; i < -ans2; ++i) putchar("SP"[i % 2]);
}
puts(".");
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3088kb
input:
3 1 2 3
output:
.
result:
ok OK 0 operations
Test #2:
score: 0
Accepted
time: 1ms
memory: 3040kb
input:
2 2 1
output:
PS.
result:
ok OK 2 operations
Test #3:
score: 0
Accepted
time: 1ms
memory: 2876kb
input:
9 3 2 4 1 5 6 7 9 8
output:
SPSP.
result:
ok OK 4 operations
Test #4:
score: 0
Accepted
time: 0ms
memory: 2872kb
input:
10 2 9 5 7 10 6 3 1 8 4
output:
PSPSPSPS.
result:
ok OK 8 operations
Test #5:
score: 0
Accepted
time: 1ms
memory: 2992kb
input:
13 9 8 5 4 3 2 1 13 12 11 10 7 6
output:
PSPSPSPS.
result:
ok OK 8 operations
Test #6:
score: 0
Accepted
time: 0ms
memory: 2992kb
input:
20 17 6 15 14 4 10 18 7 13 8 2 12 1 19 20 3 11 16 5 9
output:
PSPSPSPSPSPSPS.
result:
ok OK 14 operations
Test #7:
score: 0
Accepted
time: 1ms
memory: 2920kb
input:
100 98 85 81 18 27 10 68 48 19 2 55 51 61 20 91 54 35 22 83 75 8 5 17 23 21 95 37 15 92 50 78 82 44 39 26 87 52 66 70 74 89 4 59 40 12 88 86 43 14 80 53 46 63 3 36 97 60 58 57 96 11 67 99 41 34 47 71 72 73 79 9 94 6 1 77 25 31 7 45 100 90 32 24 13 76 16 93 38 29 69 42 84 30 28 33 56 49 62 64 65
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSP.
result:
ok OK 57 operations
Test #8:
score: 0
Accepted
time: 1ms
memory: 2880kb
input:
1000 668 554 210 852 617 846 561 95 341 893 276 224 287 1000 356 362 897 205 369 654 181 590 339 377 346 557 382 593 55 62 126 899 49 509 977 585 614 232 865 800 790 292 219 957 379 914 946 246 294 403 940 517 768 623 376 624 331 353 887 626 424 449 115 628 569 809 956 942 300 894 61 936 678 779 549...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 523 operations
Test #9:
score: 0
Accepted
time: 24ms
memory: 3476kb
input:
100000 30619 15529 4854 9258 46894 29948 59533 56945 19473 7608 42291 95532 80537 83105 70434 68130 89221 96367 26768 43837 54765 52814 88446 14950 63224 63479 11957 41446 38702 8466 85556 57724 50097 29014 17961 65178 88627 96815 80115 79096 19625 2979 51033 68224 48649 96250 3406 96433 22584 79610...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 50224 operations
Test #10:
score: 0
Accepted
time: 193ms
memory: 10552kb
input:
999999 1578 253230 300479 227250 673195 324827 649281 5836 935739 543519 370574 305888 969960 550993 463132 799873 408104 207874 140152 331798 698935 749195 181667 828624 142806 789266 207545 870039 88700 189925 952818 455047 184020 276480 107352 733977 864792 660399 680663 667372 602838 139419 6373...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 500707 operations
Test #11:
score: 0
Accepted
time: 252ms
memory: 10624kb
input:
1000000 498323 782531 234963 338622 390785 762253 966967 650745 444031 637738 473839 375864 760158 925355 805145 658434 838301 951908 714792 187771 333492 834483 290468 35807 254116 31487 26159 884256 313908 818120 709500 119492 905109 843904 538404 58932 917890 581026 96134 638691 37548 257661 5970...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 500708 operations
Test #12:
score: 0
Accepted
time: 200ms
memory: 10460kb
input:
999999 380307 675757 926537 909176 259398 767547 838631 229565 814257 719010 465888 449344 456782 751637 748757 577374 757939 757260 82870 301760 266209 725256 913345 539986 247478 544197 565340 329703 744214 414574 459491 771016 89606 959461 978510 867975 914868 284295 827692 407590 902000 767952 4...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 500707 operations
Test #13:
score: 0
Accepted
time: 247ms
memory: 10616kb
input:
1000000 172470 877546 84214 400887 576185 285780 444366 860147 679572 546507 239729 179884 641568 611945 977189 861170 861757 693499 814472 702031 255178 541730 195701 957000 328294 18206 94292 127407 263007 99562 518088 991416 202210 484246 231421 576703 773500 77020 699579 530140 726362 266475 626...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 500708 operations
Test #14:
score: 0
Accepted
time: 193ms
memory: 10620kb
input:
999999 677199 527402 260278 378779 196676 500505 577396 576982 652450 128125 354892 561405 186110 561334 565676 844764 382506 305379 925068 208078 261826 38458 770208 575208 532632 190199 485712 280726 926898 155492 38167 609603 546994 379870 692140 671912 601918 200311 856148 602748 462185 21114 95...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 500708 operations
Test #15:
score: 0
Accepted
time: 256ms
memory: 10628kb
input:
1000000 658205 878240 84096 393775 557729 717785 892649 547846 422807 378161 798924 644602 145033 110712 138504 956461 341742 765625 673610 342509 423873 129182 392707 32579 60070 466722 986494 956165 949960 516080 98315 228617 987897 101869 510240 75032 104837 57653 90089 361011 655034 87399 917195...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 500708 operations
Test #16:
score: 0
Accepted
time: 184ms
memory: 10448kb
input:
999999 560006 626515 58664 838744 331899 741740 279578 478999 629913 502367 224087 372784 152865 636238 570022 4907 690160 662704 313958 835987 577073 39974 554116 608506 928397 237166 371458 131297 716305 127503 368310 291092 204051 919187 30124 574809 66145 667573 552009 969718 524326 38216 31718 ...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 500707 operations
Test #17:
score: 0
Accepted
time: 258ms
memory: 10572kb
input:
1000000 170718 784810 674417 159793 189317 115530 524872 124667 363570 32215 429929 857870 786504 55147 260225 923095 230428 883443 620592 493326 858668 898580 49426 842887 324927 561607 693452 710499 436481 482595 832325 617114 614693 640199 419510 663725 273513 263053 841014 263727 372656 198411 3...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 500707 operations
Test #18:
score: 0
Accepted
time: 187ms
memory: 10488kb
input:
999999 916422 888632 300041 567034 646896 723598 645143 497821 300002 219825 105896 178442 118885 995990 840287 12749 420928 906993 504111 435638 296923 141718 149413 62682 648366 511386 626431 2995 841547 689727 493661 425018 231433 521401 883925 802229 422860 288294 393191 26220 36803 46033 286602...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 500707 operations
Test #19:
score: 0
Accepted
time: 261ms
memory: 10556kb
input:
1000000 46874 765821 886525 977705 548127 465831 540580 146805 506375 466370 168997 91537 183504 584871 197569 524930 989026 923955 624733 821306 59866 341573 53478 890358 290792 45795 848498 441703 988088 170699 262407 669394 988604 839083 947414 387735 667389 442038 238162 829673 242428 907422 143...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 500708 operations
Test #20:
score: 0
Accepted
time: 0ms
memory: 2880kb
input:
45 41 43 34 18 38 8 28 3 17 16 32 37 7 1 4 9 13 24 2 36 22 35 40 45 31 11 19 12 21 26 29 20 42 33 30 23 27 15 5 6 39 14 25 44 10
output:
SPSPSPSPSPSPSPSPSPSPSPSPSPS.
result:
ok OK 27 operations
Test #21:
score: 0
Accepted
time: 64ms
memory: 10488kb
input:
999997 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
ok OK 499999 operations
Test #22:
score: -100
Wrong Answer
time: 55ms
memory: 10552kb
input:
999987 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
PSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS...
result:
wrong answer Jury (499994) found answer better than participant (499995)