QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#638655#4929. Longest Unfriendly Subsequencechuangshigame0 384ms26932kbC++141.3kb2024-10-13 16:30:422024-10-13 16:30:46

Judging History

你现在查看的是最新测评结果

  • [2024-10-13 16:30:46]
  • 评测
  • 测评结果:0
  • 用时:384ms
  • 内存:26932kb
  • [2024-10-13 16:30:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int MAXN=3e5+10;
int a[MAXN],b[6],n,bp[MAXN][6];
int dp[MAXN][6];
int pre[MAXN][6],cnt[MAXN];
int main(){
    int T;cin>>T;
    while(T--){
        cin>>n;
        for(int i=0;i<=n;i++)memset(pre,0,sizeof pre),memset(cnt,0,sizeof cnt),memset(dp,0,sizeof dp),memset(bp,0,sizeof bp),cnt[i]=0;
        for(int i=1;i<=n;i++)cin>>a[i];a[0]=-1919810;
        for(int i=1;i<=n;i++){
            bool flag=false;
            for(int j=1;j<=5;j++)bp[i][j]=b[j];
            for(int j=1;j<=5;j++){
                if(a[b[j]]==a[i]){
                    flag=true;
                    b[j]=i;
                    break;
                }
            }
            if(!flag)b[1]=i;
            sort(b+1,b+6);
            
        }
        for(int i=1;i<=n;i++)for(int j=1;j<=5;j++)
            if(a[bp[i][j]]!=a[i])pre[i][++cnt[i]]=bp[i][j];
        int ans=0;
        for(int i=1;i<=n;i++){
            for(int j=0;j<=cnt[i];j++){
                int u=pre[i][j];
                for(int k=0;k<=cnt[u];k++){
                    int t=pre[u][k];    
                    if(a[t]!=a[i])dp[i][j]=max(dp[i][j],dp[u][k]+1);
                    ans=max(ans,dp[i][j]);
                }
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

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:


result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #15:

score: 6
Accepted
time: 20ms
memory: 25896kb

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: 0
Time Limit Exceeded

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
6
3
4
3
3
5
4
3
3
2
4
4
5
4
3
3
5
4
3
4
4
6
4
2
3
4
2
2
3
3
2
8
3
4
3
4
6
2
5
4
5
3
6
6
4
2
3
7
3
2
7
2
4
6
6
4
3
2
3
6
3
6
3
3
4
4
7
3
4
3
3
3
1
3
6
4
4
4
3
2
2
3
2
5
3
4
2
2
3
4
3
6
3
3
3
4
5
2
3
4
3
5
3
5
4
4
6
4
6
6
4
4
3
5
5
3
4
3
4
4
2
4
4
6
3
4
2
3
2
2
3
4
4
3
2
4
7
4
5
5
2
3
2
4
3
5
3
...

result:


Subtask #3:

score: 0
Wrong Answer

Test #19:

score: 8
Accepted
time: 383ms
memory: 25892kb

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: 8
Accepted
time: 379ms
memory: 26932kb

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
Accepted
time: 379ms
memory: 26620kb

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:

339

result:

ok single line: '339'

Test #22:

score: 8
Accepted
time: 383ms
memory: 26756kb

input:

1
500
361183277 863317163 788070566 361183277 361183277 863317163 788070566 361183277 632739493 788070566 788070566 361183277 863317163 788070566 361183277 863317163 788070566 361183277 863317163 788070566 361183277 863317163 788070566 361183277 863317163 788070566 361183277 863317163 788070566 3611...

output:

353

result:

ok single line: '353'

Test #23:

score: 8
Accepted
time: 382ms
memory: 26512kb

input:

1
500
360892412 146618517 575516781 360892412 146618517 575516781 360892412 146618517 575516781 360892412 146618517 575516781 360892412 146618517 575516781 360892412 146618517 575516781 360892412 146618517 575516781 360892412 146618517 575516781 360892412 146618517 575516781 360892412 146618517 5755...

output:

423

result:

ok single line: '423'

Test #24:

score: 8
Accepted
time: 384ms
memory: 26572kb

input:

3
68
975239020 470667175 323925950 975239020 470667175 323925950 975239020 470667175 323925950 975239020 470667175 323925950 975239020 470667175 323925950 975239020 470667175 323925950 323925950 323925950 975239020 470667175 323925950 975239020 470667175 323925950 323925950 975239020 470667175 32392...

output:

48
386
3

result:

ok 3 lines

Test #25:

score: 0
Wrong Answer
time: 384ms
memory: 26440kb

input:

3
118
150373656 793064947 635264518 635264518 709296672 793064947 635264518 709296672 709296672 709296672 793064947 635264518 709296672 793064947 635264518 709296672 793064947 793064947 635264518 709296672 793064947 793064947 635264518 709296672 793064947 635264518 709296672 793064947 635264518 7092...

output:

97
230
15

result:

wrong answer 3rd lines differ - expected: '33', found: '15'

Subtask #4:

score: 0
Time Limit Exceeded

Test #79:

score: 0
Time Limit Exceeded

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:


result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%