QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#780154 | #9787. Shrek's Song of the Swamp | myloveATRI | WA | 0ms | 7856kb | C++14 | 4.4kb | 2024-11-25 02:17:33 | 2024-11-25 02:17:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ldb=long double;
using ull=unsigned long long;
const long long inf=0x3f3f3f3f3f3f3f3f;
using i128=__int128;
const int mod=1000000007;
const long double eps=0.00000000001;
ll a[1000010];
ll f[1000010];
ll dp0[1000010];
ll dp1[1000010];
map<ll,ll>b;
map<ll,ll>c0,c1;
void solve()
{
ll n;
cin>>n;
ll mx0=0;
ll mx1=0;
for(ll i=1;i<=n;i++)cin>>a[i];
for(ll i=n;i>=1;i--)
{
if(b.count(a[i]))f[i]=1;
else f[i]=0;
b[a[i]]++;
}
for(ll i=1;i<=n;i++)
{
if(f[i]==0)
{
if(c0.count(a[i])&&c1.count(a[i]))
{
dp0[i]=max(c0[a[i]],c1[a[i]])+1;
c0[a[i]]=max(c0[a[i]],dp0[i]);
c1[a[i]]=max(c1[a[i]],dp1[i]);
mx0=max(mx0,dp0[i]);
}
else if(!c0.count(a[i])&&c1.count(a[i]))
{
dp0[i]=max(dp0[i],c1[a[i]]+1);
c0[a[i]]=max(c0[a[i]],dp0[i]);
c1[a[i]]=max(c1[a[i]],dp1[i]);
mx0=max(mx0,dp0[i]);
}
else if(c0.count(a[i])&&!c1.count(a[i]))
{
dp0[i]=max(dp0[i],c0[a[i]]+1);
c0[a[i]]=max(c0[a[i]],dp0[i]);
c1[a[i]]=max(c1[a[i]],dp1[i]);
mx0=max(mx0,dp0[i]);
}
}
else if(f[i]==1)
{
//dp1[i]
if(c0.count(a[i])&&c1.count(a[i]))
{
if(mx0==c0[a[i]]||mx0==c1[a[i]])
{
dp0[i]=max(dp0[i],mx0+1);
dp1[i]=max(dp1[i],mx0+1);
c0[a[i]]=max(c0[a[i]],dp0[i]);
c1[a[i]]=max(c1[a[i]],dp1[i]);
mx0=max(mx0,dp0[i]);
mx1=max(mx1,dp1[i]);
}
else
{
dp0[i]=max(c0[a[i]],c1[a[i]])+1;
dp1[i]=max(dp1[i],mx0+1);
c0[a[i]]=max(c0[a[i]],dp0[i]);
c1[a[i]]=max(c1[a[i]],dp1[i]);
mx0=max(mx0,dp0[i]);
mx1=max(mx1,dp1[i]);
}
}
else if(!c0.count(a[i])&&c1.count(a[i]))
{
if(mx0==c1[a[i]])
{
dp0[i]=max(dp0[i],mx0+1);
dp1[i]=max(dp1[i],mx0+1);
c0[a[i]]=max(c0[a[i]],dp0[i]);
c1[a[i]]=max(c1[a[i]],dp1[i]);
mx0=max(mx0,dp0[i]);
mx1=max(mx1,dp1[i]);
}
else
{
dp0[i]=max(dp0[i],c1[a[i]]+1);
dp1[i]=max(dp1[i],mx0+1);
c0[a[i]]=max(c0[a[i]],dp0[i]);
c1[a[i]]=max(c1[a[i]],dp1[i]);
mx0=max(mx0,dp0[i]);
mx1=max(mx1,dp1[i]);
}
}
else if(c0.count(a[i])&&!c1.count(a[i]))
{
if(mx0==c0[a[i]])
{
dp0[i]=max(dp0[i],mx0+1);
dp1[i]=max(dp1[i],mx0+1);
c0[a[i]]=max(c0[a[i]],dp0[i]);
c1[a[i]]=max(c1[a[i]],dp1[i]);
mx0=max(mx0,dp0[i]);
mx1=max(mx1,dp1[i]);
}
else
{
dp0[i]=max(dp0[i],c0[a[i]]+1);
dp1[i]=max(dp1[i],mx0+1);
c0[a[i]]=max(c0[a[i]],dp0[i]);
c1[a[i]]=max(c1[a[i]],dp1[i]);
mx0=max(mx0,dp0[i]);
mx1=max(mx1,dp1[i]);
}
}
else if(!c0.count(a[i])&&!c1.count(a[i]))
{
dp1[i]=max(dp1[i],mx0+1);
c1[a[i]]=max(c1[a[i]],dp1[i]);
c0[a[i]]=max(c0[a[i]],dp0[i]);
mx1=max(mx1,dp1[i]);
}
dp1[i]=max(dp1[i],1ll);
mx1=max(mx1,dp1[i]);
}
}
ll ans=0;
printf("%lld\n",mx0);
}
int main()
{
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
ll _=1;
// cin>>_;
while(_--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7856kb
input:
9 1 2 3 1 3 1 2 3 2
output:
4
result:
wrong answer 1st numbers differ - expected: '5', found: '4'