QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#588085 | #6528. Sequence | isirazeev | 0 | 111ms | 15084kb | C++20 | 1.4kb | 2024-09-25 00:48:55 | 2024-09-25 00:48:56 |
Judging History
answer
#include "sequence.h"
#include <vector>
#include <algorithm>
using namespace std;
const int INF = (int)1e9;
int solve(int N, vector<int> A){
int pref[N], cnt[N];
for(int i = 0; i < N; i++)
pref[i] = (A[i] == 1 ? 1 : -1) + (i > 0 ? pref[i - 1] : 0);
for(int i = 0; i < N; i++)
cnt[i] = (i > 0 ? cnt[i - 1] : 0) + (A[i] == 1);
int mx[N], res = 0;
for(int i = N - 1; i >= 0; i--)
mx[i] = max((i + 1 < N ? mx[i + 1] : -INF), pref[i]);
for(int i = N - 2; i >= -1; i--){
int at_least = (i >= 0 ? -pref[i] : 0);
int l = i + 1, r = N;
while(r - l > 1){
int mid = (l + r) / 2;
if(mx[mid] >= at_least) l = mid;
else r = mid;
}
if(mx[l] >= at_least) res = max(res, cnt[l] - (i >= 0 ? cnt[i] : 0));
}
return res;
}
int sequence(int N, std::vector<int> A) {
sort(A.begin(), A.end());
if(A[N - 1] <= 2){
int c1 = 0, c2 = 0;
for(int i = 0; i < N; i++)
c1 += (A[i] == 1), c2 += (A[i] == 2);
return max(c1, c2);
}
vector<int> medians;
if(N % 2 == 1) medians = {A[N / 2]};
else medians = {A[N / 2 - 1], A[N / 2]};
int res = 0;
for(int x : medians){
int cnt = 0;
for(int j = 0; j < N; j++)
cnt += (A[j] == x);
res = max(res, cnt);
}
res = max(res, solve(N, A));
for(int i = 0; i < (int)A.size(); i++)
A[i] = 4 - A[i];
res = max(res, solve(N, A));
return res;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 11
Accepted
time: 0ms
memory: 4076kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 98 92 89 9 86 80 6 42 20 84 82 46 56 52 30 44 39 35 82 57 33 18 38 32 63 27 55 33 44 41 39 62 26 46 59 21 85 36 60 7 36 50 22 87 83 71 27 4 3 87 47 17 62 70 24 9 20 81 21 57 50 13 32 68 70 11 95 5 56 64 90 47 42 44 72 71 46 84 72 56 63 37 35 80 78 4 54 74 79 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 3
result:
ok
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 4080kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 96 1 6 1 4 6 2 5 1 1 2 8 2 4 4 1 9 8 9 8 5 3 6 6 4 9 4 2 8 8 8 2 9 1 3 6 6 1 6 5 5 3 7 9 7 1 8 5 6 8 5 1 1 4 9 6 7 2 6 6 7 4 2 2 8 5 6 4 8 2 6 5 8 6 1 6 2 1 3 4 6 3 6 8 2 5 7 8 2 4 1 5 6 2 3 6 6
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 13
result:
wrong answer 1st lines differ - on the 1st token, expected: '18', found: '13'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #20:
score: 0
Wrong Answer
time: 111ms
memory: 15080kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499996 53 78 81 111 119 124 126 130 164 175 219 227 233 249 282 298 332 341 348 436 437 448 452 455 462 465 495 535 557 558 576 600 620 627 632 642 643 659 695 696 713 730 743 805 816 865 869 872 875 882 883 902 924 937 990 998 1025 1092 1137 1145 1166 1176 1...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 2
result:
wrong answer 1st lines differ - on the 1st token, expected: '8', found: '2'
Subtask #4:
score: 0
Wrong Answer
Test #28:
score: 12
Accepted
time: 89ms
memory: 15068kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499999 2 1 2 2 2 1 2 3 1 3 1 2 2 1 2 1 1 2 1 1 2 1 1 2 1 2 1 1 1 1 1 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 3 3 3 3 1 3 1 2 2 1 1 1 3 1 3 1 1 2 1 2 2 2 1 3 2 1 1 1 2 2 1 2 2 3 1 2 2 1 2 2 1 1 2 1 1 2 2 1 2 2 1 1 1 1 2 2 1 1 1 1 1 2 1 1 2 1 1 3 2 1 1 1 3 1 1 2 1 3 1 1 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 277713
result:
ok
Test #29:
score: 0
Wrong Answer
time: 89ms
memory: 14984kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499999 2 3 1 3 3 3 1 2 3 3 3 2 2 1 1 3 1 2 1 3 3 3 2 2 2 2 3 3 2 2 2 1 1 2 3 3 1 3 1 1 2 3 3 1 1 1 2 1 1 1 2 3 2 2 1 2 1 1 3 1 1 1 3 1 1 2 1 3 2 3 1 3 1 3 3 2 1 3 1 2 1 3 2 1 1 2 3 1 2 1 3 3 1 2 1 3 3 3 2 3 2 1 1 2 1 2 3 1 1 2 2 1 3 2 3 2 3 2 2 1 3 2 3 1 3 3 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 166513
result:
wrong answer 1st lines differ - on the 1st token, expected: '166105', found: '166513'
Subtask #5:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 110ms
memory: 15084kb
input:
8wq90di9812978rqwiok0k0o21klklm21oiwi121 499999 490225 471440 499001 369862 494577 479599 486292 476071 471988 486939 482356 482290 497141 488452 495446 494292 404798 493826 482595 481107 447196 477441 418064 495941 448927 483365 418585 489220 443224 482574 487957 467944 493253 472016 475543 442250 ...
output:
nfp39szm23aa01pcmyosi03slwpeksnfjri3opqp OK 2
result:
wrong answer 1st lines differ - on the 1st token, expected: '1', found: '2'
Subtask #6:
score: 0
Skipped
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%