Submission #1273738

#TimeUsernameProblemLanguageResultExecution timeMemory
1273738thelegendary08Monochrome Points (JOI20_monochrome)C++17
35 / 100
2096 ms17476 KiB
#include<bits/stdc++.h> // #include<atcoder/modint> #define pb push_back #define mp make_pair #define rs resize #define ft front() #define bk back() #define int long long #define vi vector<int> #define vvi vector<vector<int>> #define pii pair<int, int> #define vpii vector<pair<int, int>> #define vc vector<char> #define vb vector<bool> #define mii map<int,int> #define f0r(i,n) for(int i=0;i<n;i++) #define FOR(i,k,n) for(int i=k;i<n;i++) #define r0f(i,n) for(int i = n-1; i >= 0; i--) #define R0F(i,k,n) for(int i = n-1; i >= k; i--) #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define in(a) int a; cin>>a #define in2(a,b) int a,b; cin>>a>>b #define in3(a,b,c) int a,b,c; cin>>a>>b>>c #define in4(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d #define vin(v,n); vi v(n); f0r(i,n){cin>>v[i];} #define out(a) cout<<a<<'\n' #define out2(a,b) cout<<a<<' '<<b<<'\n' #define out3(a,b,c) cout<<a<<' '<<b<<' '<<c<<'\n' #define out4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<'\n' #define pout(a) cout<<a.first<<' '<<a.second<<'\n' #define vout(v) for(auto u : v){cout<<u<<' ';} cout<<endl #define dout(a) cout<<a<<' '<<#a<<endl #define dout2(a,b) cout<<a<<' '<<#a<<' '<<b<<' '<<#b<<endl #define yn(x); if(x){cout<<"YES"<<'\n';}else{cout<<"NO"<<'\n';} #define p2(x) (1LL << (x)) #define pct(x) (__builtin_popcountll(x)) #define ist(x,y) ((x >> y) & 1) template<class T, class U> bool ckmin(T& a, const U& b) { return (T)b < a ? a = (T)b, 1 : 0; } template<class T, class U> bool ckmax(T& a, const U& b) { return a < (T)b ? a = (T)b, 1 : 0; } const int leg = 1e9 + 7; const int mod = 998244353; using namespace std; // using namespace atcoder; // using mint = modint998244353; bool cmp(pii a, pii b){ if(a.first != b.first)return a.first < b.first; else return a.second > b.second; } struct segtree{ int n; vi tree; segtree(int x){ n = x; tree.rs(2 * n + 5); } void add(int k, int x){ k += n; tree[k] += x; for(k/=2;k>=1;k/=2)tree[k] = tree[k*2] + tree[k*2+1]; } int quer(int l, int r){ l += n; r += n; int ret = 0; while(l <= r){ if(l % 2)ret += tree[l++]; if(r % 2 == 0)ret += tree[r--]; l/=2;r/=2; } // dout2(l,r); dout(ret); return ret; } }; int n; int solve(vpii v){ sort(all(v), cmp); // for(auto u : v)pout(u); cout<<'\n'; segtree S = segtree(2*n); int nst = 0, ans = -n; f0r(i,n){ nst += S.quer(v[i].second + 1, 2*n-1); S.add(v[i].second, 1); ans += v[i].second - v[i].first; } ans -= nst * 2; ans /= 2; return ans; } signed main(){ ios::sync_with_stdio(false); cin.tie(NULL); //ifstream cin(".in"); //ofstream cout(".out"); cin>>n; string s; cin>>s; vi a, b; f0r(i, 2*n){if(s[i] == 'W')a.pb(i); else b.pb(i);} int ans = 0; f0r(i, n+1){ //pair first i whites with last i blacks, pair first n-i blacks with last n-i whites vpii tmp; f0r(j, i)tmp.pb(mp(a[j], b[j + n - i])); f0r(j, n-i)tmp.pb(mp(b[j], a[j+i])); ckmax(ans, solve(tmp)); } out(ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...