This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX_VAL=200*1000+5;
int nbVal;
vector<int> initType;
string valDeb;
int cumu[MAX_VAL];
int compt(vector<int> listeBla,vector<int> listeNoir) {
int nbInter=0,temp,mini,maxi;
for (int i=0;i<nbVal;i++) {
mini=min(listeBla[i],listeNoir[i]);
maxi=max(listeBla[i],listeNoir[i]);
temp=min(maxi-mini-1,2*nbVal-maxi-1+mini);
//cout<<listeBla[i]<<" "<<listeNoir[i]<<" "<<temp<<" ";
nbInter+=temp;
}
return nbInter/2;
}
int calc(vector<int> typeSom) {
int rep=0;
vector<int> listeBla,listeNoir;
for (int i=0;i<2*nbVal;i++) {
if (typeSom[i]==0) {
listeBla.push_back(i);
}
else {
listeNoir.push_back(i);
}
}
for (int j=0;j<nbVal;j++) {
cumu[j]=-nbVal;
}
int autre;
for (int i=0;i<nbVal;i++) {
for (int j=0;j<nbVal;j++) {
autre=listeNoir[(i+j)%nbVal];
if (listeBla[i]<autre) {
if (autre-listeBla[i]<nbVal) {
cumu[j]-=listeBla[i];
}
else {
cumu[j]+=listeBla[i];
}
}
else {
if (listeBla[i]-autre<nbVal) {
cumu[j]+=listeBla[i];
}
else {
cumu[j]+=2*nbVal-listeBla[i];
}
}
}
}
for (int i=0;i<nbVal;i++) {
for (int j=0;j<nbVal;j++) {
autre=listeBla[(i-j+nbVal)%nbVal];
if (listeNoir[i]<autre) {
if (autre-listeNoir[i]<nbVal) {
cumu[j]-=listeNoir[i];
}
else {
cumu[j]+=listeNoir[i];
}
}
else {
if (listeNoir[i]-autre<nbVal) {
cumu[j]+=listeNoir[i];
}
else {
cumu[j]+=2*nbVal-listeNoir[i];
}
}
}
}
for (int j=0;j<nbVal;j++) {
rep=max(rep,cumu[j]/2);
}
return rep;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>nbVal;
cin>>valDeb;
for (int i=0;i<2*nbVal;i++) {
if (valDeb[i]=='W') {
initType.push_back(0);
}
else {
initType.push_back(1);
}
}
cout<<calc(initType)<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |