QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740337 | #5035. foo~ | zwh2008 | 0 | 12ms | 18352kb | C++14 | 1.2kb | 2024-11-13 09:08:49 | 2024-11-13 09:08:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pi=pair<int,int>;
#define fi first
#define se second
const int N=6e5+5;
int n,m,ans,a[N],a0[N],st[N],f[N],g[N],g1[N],g2[N];
template<class T>void gmax(T&x,T y){x=(x>y?x:y);}
void slv() {
memset(f,-0x3f,sizeof(f)),f[0]=0;
for(int o=1;o<=m;o++) {
memcpy(g,f,sizeof(g)),memset(f,-0x3f,sizeof(f));
int mx=g[0],top=0,Mx=-1e9;
for(int i=1;i<=n;i++) {
g1[a[i]]=g[i-1]+1,g2[a[i]]=mx+1;
while(top&&a[st[top]]<a[i]) {
gmax(g1[a[i]],g1[a[st[top]]]+1);
top--;
}
if(top)gmax(g2[a[i]],g2[a[st[top]]]+1);
gmax(Mx,g1[a[i]]);
f[i]=max(Mx,g2[a[i]]),mx=max(mx,g[i]),st[++top]=i;
}
}ans=max(ans,f[n]);
}
int main() {
#ifndef ONLINE_JUDGE
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>m;int p0=0;
for(int i=1;i<=n;i++)cin>>a0[i],p0=(a0[i]==1?i:p0);
for(int i=1;i<=n;i++)a[i]=a0[(i-2+p0)%n+1];
slv(),reverse(a0+1,a0+n+1),p0=n+1-p0;
for(int i=1;i<=n;i++)a[i]=a0[(i-2+p0)%n+1];
slv(),cout<<ans<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 0ms
memory: 15944kb
input:
23 6 16 20 22 4 21 10 3 7 5 8 15 12 9 1 6 17 23 13 11 19 18 14 2
output:
20
result:
ok "20"
Test #2:
score: 10
Accepted
time: 0ms
memory: 15920kb
input:
13 6 13 9 3 4 12 6 5 1 8 10 11 7 2
output:
13
result:
ok "13"
Test #3:
score: 10
Accepted
time: 0ms
memory: 18024kb
input:
25 3 25 2 3 19 5 6 7 11 8 10 9 20 4 14 21 1 17 12 13 18 15 22 23 16 24
output:
16
result:
ok "16"
Test #4:
score: 10
Accepted
time: 3ms
memory: 18052kb
input:
25 9 1 11 10 23 9 24 7 8 19 3 5 21 18 12 15 16 17 13 2 20 14 22 4 6 25
output:
23
result:
ok "23"
Test #5:
score: 10
Accepted
time: 0ms
memory: 15924kb
input:
13 2 1 4 2 3 5 6 7 8 9 10 12 11 13
output:
12
result:
ok "12"
Test #6:
score: 10
Accepted
time: 4ms
memory: 16012kb
input:
17 5 4 2 3 6 5 1 7 8 13 16 11 12 9 14 15 10 17
output:
15
result:
ok "15"
Test #7:
score: 10
Accepted
time: 0ms
memory: 15880kb
input:
8 2 1 2 5 6 3 4 7 8
output:
8
result:
ok "8"
Test #8:
score: 10
Accepted
time: 4ms
memory: 15920kb
input:
11 5 3 11 2 10 6 5 1 4 8 7 9
output:
11
result:
ok "11"
Test #9:
score: 10
Accepted
time: 2ms
memory: 15944kb
input:
10 1 5 3 4 1 10 8 9 6 7 2
output:
6
result:
ok "6"
Test #10:
score: 10
Accepted
time: 2ms
memory: 15952kb
input:
16 2 15 12 14 9 11 13 1 3 10 8 5 2 16 4 6 7
output:
9
result:
ok "9"
Test #11:
score: 10
Accepted
time: 3ms
memory: 15904kb
input:
6 3 4 1 5 6 2 3
output:
6
result:
ok "6"
Test #12:
score: 10
Accepted
time: 0ms
memory: 17992kb
input:
1 1 1
output:
1
result:
ok "1"
Test #13:
score: 10
Accepted
time: 4ms
memory: 15952kb
input:
16 5 7 14 13 16 10 1 9 11 3 8 2 4 5 15 12 6
output:
14
result:
ok "14"
Test #14:
score: 0
Wrong Answer
time: 3ms
memory: 15884kb
input:
10 3 10 1 7 2 8 6 9 5 4 3
output:
8
result:
wrong answer 1st words differ - expected: '9', found: '8'
Subtask #2:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 4ms
memory: 18352kb
input:
93943 1 87243 48984 50611 19218 77699 25025 85769 28141 13380 34875 42459 66419 53472 4367 48292 16894 92171 87263 42527 67085 30687 29235 27515 81053 31421 34864 83591 70491 75344 7026 50250 63402 26773 5330 36308 76399 80032 15501 16205 71750 73964 67876 68901 70548 2043 79979 89479 19784 38838 44...
output:
14
result:
wrong answer 1st words differ - expected: '25', found: '14'
Subtask #3:
score: 0
Wrong Answer
Test #36:
score: 20
Accepted
time: 12ms
memory: 15968kb
input:
1992 25 144 612 1315 1966 1779 1773 1529 625 36 1849 1783 1441 1388 1558 1258 724 137 397 542 353 1162 1213 406 792 1317 882 994 298 1864 1969 103 449 508 1501 89 1721 195 778 657 222 1152 1780 613 743 1206 694 829 142 69 1973 1465 1343 655 1540 155 146 350 491 759 1695 1082 1357 1329 1745 232 1850 ...
output:
237
result:
ok "237"
Test #37:
score: 20
Accepted
time: 11ms
memory: 15888kb
input:
1992 17 785 891 1027 155 773 587 1829 255 1239 1893 1854 158 349 370 1134 1739 1186 11 1099 1149 481 361 1101 1359 1773 1568 157 1011 79 555 254 285 1260 1722 1684 577 1054 1932 590 1804 414 1415 376 1699 26 971 1554 1504 1987 1327 1184 610 652 1432 206 129 315 1390 1946 64 910 962 1189 326 497 1580...
output:
172
result:
ok "172"
Test #38:
score: 20
Accepted
time: 4ms
memory: 15872kb
input:
46 11 41 44 2 9 30 46 28 14 12 20 38 37 19 6 13 7 26 4 34 15 32 5 35 1 25 8 29 45 31 22 18 24 33 42 21 17 39 10 43 11 23 27 36 3 40 16
output:
38
result:
ok "38"
Test #39:
score: 20
Accepted
time: 11ms
memory: 15952kb
input:
53 18 29 23 32 11 24 27 28 16 6 9 3 20 8 38 43 49 18 26 41 53 31 19 48 34 44 52 45 5 30 17 2 13 15 40 1 50 21 14 4 22 51 35 39 7 47 25 10 12 33 42 36 46 37
output:
49
result:
ok "49"
Test #40:
score: 20
Accepted
time: 11ms
memory: 15944kb
input:
55 25 42 41 51 1 6 49 28 12 33 23 31 47 19 24 48 21 54 16 14 3 26 43 18 5 45 29 50 15 44 35 7 40 9 53 10 32 17 36 4 34 20 38 37 8 55 2 11 39 30 22 52 27 13 46 25
output:
55
result:
ok "55"
Test #41:
score: 0
Wrong Answer
time: 3ms
memory: 17984kb
input:
78 9 44 4 68 49 20 16 67 3 70 40 25 6 46 27 65 10 77 55 12 78 2 31 22 71 74 30 41 53 34 47 32 36 57 19 18 1 26 69 11 52 72 14 8 17 56 51 42 43 62 58 35 76 66 23 54 73 63 75 39 37 28 5 9 24 21 48 64 61 29 45 38 13 59 50 15 7 33 60
output:
41
result:
wrong answer 1st words differ - expected: '42', found: '41'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
0%