QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#478636 | #4929. Longest Unfriendly Subsequence | rr | 0 | 38ms | 5924kb | C++14 | 1.8kb | 2024-07-15 08:41:18 | 2024-07-15 08:41:19 |
Judging History
answer
#include<iostream>
#include<cstdio>
using namespace std;
int t,n;
const int N=3e5+10;
int a[N];
int f[N];
struct aa{
int val,id;
int zdz,cdz;
int zdid,cdid;
};
void prt(aa x){
cout<<x.id<<" "<<x.val<<" "<<x.zdid<<" "<<x.zdz<<" "<<x.cdid<<" "<<x.cdz<<endl;
}
aa dp[10];
int main(){
cin>>t;
while(t--){
cin>>n;
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
dp[1].val=a[1];
dp[1].id=1;
dp[0].val=1;
dp[1].zdz=1;
dp[1].zdid=a[1];
for(int i=2;i<=n;i++){
aa fn;
fn.cdid=fn.cdz=fn.id=fn.val=fn.zdid=fn.zdz=0;
fn.val=a[i];
fn.id=i;
for(int j=1;j<=dp[0].val;j++){
if(dp[j].val==a[i])continue;
if(dp[j].zdid==a[i]){
if(!dp[j].cdz)continue;
else {
f[i]=max(f[i],dp[j].cdz+1);
if(f[i]>fn.zdz){
fn.zdz=f[i];
fn.zdid=dp[j].val;
}else{
if(f[i]>fn.cdz){
fn.cdz=f[i];
fn.cdid=dp[j].val;
}
}
}
}else{
f[i]=max(f[i],dp[j].zdz+1);
if(f[i]>fn.zdz){
fn.zdz=f[i];
fn.zdid=dp[j].val;
}else{
if(f[i]>fn.cdz){
fn.cdz=f[i];
fn.cdid=dp[j].val;
}
}
}
}
int flag=0,zxid=999999999,zxidd;
for(int j=1;j<=dp[0].val;j++){
if(dp[j].val==a[i])flag=j;
if(dp[j].id<zxid){
zxid=dp[j].id;
zxidd=j;
}
//prt(dp[j]);
}
// puts("");
if(flag){
dp[flag]=fn;
continue;
}
if(dp[0].val<5){
dp[0].val++;
dp[dp[0].val]=fn;
}
else dp[zxidd]=fn;
}
int maxans=0;
for(int i=1;i<=n;i++)maxans=max(maxans,f[i]);
cout<<maxans<<endl;
aa ff;
ff.cdid=ff.cdz=ff.id=ff.val=ff.zdid=ff.zdz=0;
for(int i=0;i<=5;i++)dp[i]=ff;
for
(int i=1;i<=n;i++)f[i]=0;
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 15ms
memory: 5252kb
input:
1 200000 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 259021863 2...
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #15:
score: 6
Accepted
time: 0ms
memory: 3744kb
input:
3 5 1 2 1 2 1 7 1 2 3 2 1 2 3 8 1 10 10 1 1 100 100 1
output:
2 6 4
result:
ok 3 lines
Test #16:
score: -6
Wrong Answer
time: 38ms
memory: 3800kb
input:
28653 6 372076545 832760265 372076545 644300403 644300403 644300403 8 540046638 375129642 863244619 863244619 375129642 540046638 540046638 540046638 6 142783193 508154499 871683432 71368434 871683432 871683432 8 760894385 984189193 760894385 323542350 984189193 760894385 323542350 323542350 6 84093...
output:
3 4 4 4 3 3 2 4 5 4 5 4 1 4 5 5 4 2 5 5 3 4 3 5 6 4 1 2 4 3 1 2 4 2 8 4 6 5 4 6 4 5 4 5 4 5 6 2 2 3 8 5 3 7 2 4 6 6 4 3 3 3 6 2 6 4 2 4 4 7 3 3 5 4 5 0 2 6 3 3 3 4 1 3 3 1 5 3 4 1 2 2 3 2 5 2 5 2 3 6 2 2 3 3 5 2 4 2 3 6 5 5 6 4 5 4 5 5 3 3 2 3 3 1 4 3 6 5 4 3 3 2 2 5 3 5 2 3 3 7 3 5 4 1 5 1 2 4 4 4 ...
result:
wrong answer 4th lines differ - expected: '6', found: '4'
Subtask #3:
score: 0
Wrong Answer
Test #19:
score: 8
Accepted
time: 0ms
memory: 3688kb
input:
1 500 537076440 691668159 871942500 537076440 537076440 691668159 871942500 871942500 537076440 691668159 871942500 537076440 691668159 871942500 537076440 691668159 871942500 537076440 691668159 871942500 537076440 691668159 871942500 871942500 537076440 691668159 871942500 537076440 537076440 6916...
output:
361
result:
ok single line: '361'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
1 500 584142119 101442702 335815880 584142119 101442702 335815880 584142119 101442702 335815880 584142119 101442702 335815880 584142119 101442702 101442702 335815880 335815880 584142119 584142119 101442702 101442702 335815880 584142119 101442702 335815880 584142119 101442702 335815880 584142119 1014...
output:
394
result:
ok single line: '394'
Test #21:
score: -8
Wrong Answer
time: 0ms
memory: 3740kb
input:
1 500 296341737 806184542 989331127 989331127 296341737 806184542 455929030 296341737 806184542 806184542 806184542 989331127 296341737 806184542 989331127 296341737 806184542 989331127 296341737 806184542 989331127 296341737 806184542 806184542 989331127 296341737 296341737 296341737 806184542 9893...
output:
439
result:
wrong answer 1st lines differ - expected: '339', found: '439'
Subtask #4:
score: 0
Wrong Answer
Test #79:
score: 10
Accepted
time: 12ms
memory: 5320kb
input:
1 200000 1 3 3 2 2 3 3 1 2 3 1 1 3 3 3 2 1 1 2 3 2 1 3 3 3 1 2 2 1 3 1 2 1 2 3 2 3 3 2 2 3 2 3 2 3 1 1 1 1 1 3 1 3 2 3 3 3 3 1 3 2 1 3 2 3 2 3 1 1 1 1 3 3 2 3 2 1 2 2 3 2 3 2 2 2 2 2 2 3 2 1 2 2 1 1 3 2 1 2 1 1 3 3 3 2 1 2 2 2 1 3 3 2 3 2 1 3 3 2 2 1 3 1 3 2 1 2 3 2 1 2 3 2 2 3 2 1 2 1 1 1 1 1 1 1 3...
output:
66691
result:
ok single line: '66691'
Test #80:
score: -10
Wrong Answer
time: 11ms
memory: 5924kb
input:
1 200000 2 2 3 3 3 2 1 2 1 1 1 3 3 2 3 3 1 3 2 3 3 3 2 1 2 2 2 2 1 1 2 2 1 3 1 3 1 3 3 1 2 1 1 2 1 1 2 1 1 1 1 2 2 1 3 2 3 3 2 3 2 3 1 1 1 1 2 3 1 2 1 1 2 3 2 3 3 2 1 2 1 1 3 3 3 1 2 3 1 3 1 3 1 1 2 1 3 2 1 1 3 2 1 1 3 2 3 2 3 2 1 3 2 2 2 1 2 2 1 3 3 1 3 1 2 3 1 1 2 2 2 1 3 1 1 3 3 2 3 2 1 3 1 1 1 3...
output:
66402
result:
wrong answer 1st lines differ - expected: '66403', found: '66402'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #3:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%