https://i2.wp.com/eblogarithm.com/wp-content/uploads/2017/07/Codeforces-Round-416-Div-2-problem-C-Vladik-and-Memorable-Trip-Solution-In-CC1.png?fit=640%2C360

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 4 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: