Submission #850569

#TimeUsernameProblemLanguageResultExecution timeMemory
850569oscar1fMonochrome Points (JOI20_monochrome)C++17
35 / 100
2039 ms15580 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]; void addInter(int deb,int fin,int val) { //cout<<deb<<" "<<fin<<" "<<val<<endl; if (deb>fin) { addInter(deb,nbVal,val); addInter(0,fin,val); } for (int i=deb;i<fin;i++) { cumu[i]+=val; } } void add(int deb,int fin,int val) { if (fin-deb>=nbVal) { addInter(0,nbVal,val); } else { addInter((deb+nbVal)%nbVal,(fin+nbVal)%nbVal,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; } } add(0-i,deb-i,2*nbVal-listeBla[i]); add(deb-i,premSup-i,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; } } add(premSup-i,deb-i,-listeBla[i]); add(deb-i,nbVal-i,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; } } add(i-deb+1,i-0+1,2*nbVal-listeNoir[i]); add(i-premSup+1,i-deb+1,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; } } add(i-deb+1,i-premSup+1,-listeNoir[i]); add(i-nbVal+1,i-deb+1,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...