Codeforces Round #416 (Div. 2), problem: (C) Vladik and Memorable Trip Solution In C/C++

#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
int n,a[5005],c[5005],f[5005];
scanf(“%d”,&n);
for(int i=0;i<n;i++)scanf(“%d”,a+i),c[a[i]]++;
for(int i=0;i<n;i++){
int v[5005]={0},temp=0,xo=0;
for(int j=i;j>=0;j–){
if(v[a[j]]==0)v[a[j]]=1,temp+=c[a[j]],xo^=a[j];
f[i+1]=max(f[i+1],f[j]+(–temp?0:xo));
}
}
printf(“%d”,f[n]);
return 0;
}

(Visited 25 times, 1 visits today)

About the Author:

Leave A Comment