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,deb,fin,mid,premSup;
for (int i=0;i<nbVal;i++) {
//cout<<i<<endl;
deb=0;
fin=nbVal;
while (deb!=fin) {
mid=(deb+fin)/2;
if (listeNoir[mid]<listeBla[i]) {
deb=mid+1;
}
else {
fin=mid;
}
}
premSup=deb;
if (premSup>0) {
deb=0;
fin=premSup-1;
while (deb!=fin) {
mid=(deb+fin)/2;
if (listeBla[i]-listeNoir[mid]<nbVal) {
fin=mid;
}
else {
deb=mid+1;
}
}
for (int j=0;j<deb;j++) {
cumu[(j-i+nbVal)%nbVal]+=2*nbVal-listeBla[i];
//cout<<"D"<<j<<" ";
}
for (int j=deb;j<premSup;j++) {
cumu[(j-i+nbVal)%nbVal]+=listeBla[i];
//cout<<"C"<<j<<" ";
}
//cout<<deb<<" ";
}
//cout<<premSup<<" ";
if (premSup<nbVal) {
deb=premSup;
fin=nbVal;
while (deb!=fin) {
mid=(deb+fin)/2;
if (listeNoir[mid]-listeBla[i]>=nbVal) {
fin=mid;
}
else {
deb=mid+1;
}
}
//cout<<deb<<" ";
for (int j=premSup;j<deb;j++) {
cumu[(j-i+nbVal)%nbVal]-=listeBla[i];
//cout<<"A"<<j<<" ";
}
for (int j=deb;j<nbVal;j++) {
cumu[(j-i+nbVal)%nbVal]+=listeBla[i];
//cout<<"B"<<j<<" ";
}
}
//cout<<endl;
/*for (int j=0;j<nbVal;j++) {
autre=listeNoir[j];
if (listeBla[i]<autre) {
if (autre-listeBla[i]<nbVal) {
//cumu[(j-i+nbVal)%nbVal]-=listeBla[i];
cout<<"A"<<j<<" ";
}
else {
//cumu[(j-i+nbVal)%nbVal]+=listeBla[i];
cout<<"B"<<j<<" ";
}
}
else {
if (listeBla[i]-autre<nbVal) {
//cumu[(j-i+nbVal)%nbVal]+=listeBla[i];
cout<<"C"<<j<<" ";
}
else {
//cumu[(j-i+nbVal)%nbVal]+=2*nbVal-listeBla[i];
cout<<"D"<<j<<" ";
}
}
}
cout<<endl;
cout<<endl;*/
}
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... |