Submission #443112

#TimeUsernameProblemLanguageResultExecution timeMemory
443112JasiekstrzMonochrome Points (JOI20_monochrome)C++17
0 / 100
1 ms204 KiB
#include<bits/stdc++.h> #define fi first #define se second using namespace std; const int N=4e5; int mtch[N+10]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; string s; cin>>s; int b=2*n-1,w=2*n-1; int bw=0,ww=0; long long ans=0; for(int i=n-1;i>=0;i--) { if(s[i]=='B') { while(s[w]!='W') { ww+=mtch[w]; w--; } //cerr<<"w "<<w<<"\n"; ans+=ww; mtch[w]++; if(b<w) bw++; ww++; w--; } else { while(s[b]!='B') { bw+=mtch[b]; b--; } //cerr<<"b "<<b<<"\n"; ans+=bw; mtch[b]++; if(w<b) ww++; bw++; b--; } //cerr<<ans<<"\n"; } cout<<ans<<"\n"; 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...