QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#780876#9787. Shrek's Song of the SwampGenshinImpactShutdown#WA 1ms5908kbC++14666b2024-11-25 13:47:342024-11-25 13:47:34

Judging History

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

  • [2024-11-25 13:47:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5908kb
  • [2024-11-25 13:47:34]
  • 提交

answer

#include<bits/stdc++.h>
#define All(x) x.begin(),x.end()
using namespace std;
using ull=unsigned long long;
using ll=long long;
using bint=__int128;
using ld=long double;
using pii=pair<int,int>;
using vi=vector<int>;
const int N=1e6+5;
int n,a[N],f[N],g[N],ls[N];
unordered_map<int,int> tg;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
    {
        ls[i]=tg[a[i]];
        tg[a[i]]=i;
    }for(int i=1;i<=n;i++)
    {
        f[i]=f[ls[i]]+1;
        if(ls[i])f[i]=max(f[i],g[ls[i]-1]+2);
        g[i]=max(g[i-1],f[i]);
    }cout<<g[n]<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5908kb

input:

9
1 2 3 1 3 1 2 3 2

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5680kb

input:

6
3 4 10 1 -3 5

output:

1

result:

wrong answer 1st numbers differ - expected: '0', found: '1'