Submission #850554

#TimeUsernameProblemLanguageResultExecution timeMemory
850554oscar1fMonochrome Points (JOI20_monochrome)C++17
35 / 100
2028 ms14556 KiB
#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 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 deb,fin,mid,premSup; for (int i=0;i<nbVal;i++) { 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; 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]; } for (int j=deb;j<premSup;j++) { cumu[(j-i+nbVal)%nbVal]+=listeBla[i]; } } 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; } } for (int j=premSup;j<deb;j++) { cumu[(j-i+nbVal)%nbVal]-=listeBla[i]; } for (int j=deb;j<nbVal;j++) { cumu[(j-i+nbVal)%nbVal]+=listeBla[i]; } } } for (int i=0;i<nbVal;i++) { deb=0; fin=nbVal; while (deb!=fin) { mid=(deb+fin)/2; if (listeBla[mid]<listeNoir[i]) { deb=mid+1; } else { fin=mid; } } premSup=deb; if (premSup>0) { deb=0; fin=premSup; while (deb!=fin) { mid=(deb+fin)/2; if (listeNoir[i]-listeBla[mid]<nbVal) { fin=mid; } else { deb=mid+1; } } for (int j=0;j<deb;j++) { cumu[(i-j+nbVal)%nbVal]+=2*nbVal-listeNoir[i]; } for (int j=deb;j<premSup;j++) { cumu[(i-j+nbVal)%nbVal]+=listeNoir[i]; } } if (premSup<nbVal) { deb=premSup; fin=nbVal; while (deb!=fin) { mid=(deb+fin)/2; if (listeBla[mid]-listeNoir[i]>=nbVal) { fin=mid; } else { deb=mid+1; } } for (int j=premSup;j<deb;j++) { cumu[(i-j+nbVal)%nbVal]-=listeNoir[i]; } for (int j=deb;j<nbVal;j++) { cumu[(i-j+nbVal)%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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...