Submission #537864

#TimeUsernameProblemLanguageResultExecution timeMemory
537864michaoMonochrome Points (JOI20_monochrome)C++14
35 / 100
2088 ms4328 KiB
#include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; const int MAX=2e5+5; vi b,w; char s[MAX*2]; int ans=0; int n; int ile(int x,int y){ if (x>y)swap(x,y); int between=y-x-1; return min(n*2-2-between,between); } int f(int shift){ int sum=0; assert(sz(b)==sz(w) && sz(b)==n); for (int i=0;i<n;i++){ int x=b[i]; int y=w[(i+shift)%n]; //if (shift==1)cout<<"TERAZ "<<x<<" "<<y<<" "<<ile(x,y)<<"\n"; sum+=ile(x,y); } return sum/2; } int32_t main(){ BOOST; cin>>n; for (int i=0;i<n*2;i++){ cin>>s[i]; if (s[i]=='B')b.pb(i); else w.pb(i); } for (int i=0;i<=n-1;i++){ ans=max(ans,f(i)); } cout<<ans; 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...