# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
704094 | 2023-03-01T14:38:34 Z | 1075508020060209tc | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 8 ms | 8360 KB |
//#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #define int long long #define X first #define Y second int lowbit(int x){return x&-x;} int bit[500005]; int upd(int pl,int v){ while(pl<=500000){ bit[pl]+=v; pl+=lowbit(pl); } } int qsum(int x){ int ret=0; while(x){ ret+=bit[x]; x-=lowbit(x); } return ret; } vector<int>pr; vector<int>gr; vector<int>yr; int n; string s; signed main(){ cin>>n>>s; s="*"+s; for(int i=1;i<=n;i++){ if(s[i]=='R'){ pr.push_back(i); } if(s[i]=='G'){ gr.push_back(i); } } if(pr.size()>=gr.size()+2){ cout<<-1<<endl; return 0; } if(gr.size()>=pr.size()+2){ cout<<-1<<endl; return 0; } int fans=1e16; if(gr.size()>=pr.size()){ int ans=0; for(int i=1;i<=n;i++){ if(i%2==1){ int pl=gr[(i+1)/2-1]; ans=pl-i+qsum(n)-qsum(pl); upd(pl,1); }else{ int pl=pr[i/2-1]; ans=pl-i+qsum(n)-qsum(pl); upd(pl,1); } } fans=ans; } for(int i=1;i<=500000;i++){bit[i]=0;} if(gr.size()<=pr.size()){ int ans=0; for(int i=1;i<=n;i++){ if(i%2==0){ int pl=gr[(i+1)/2-1]; ans=pl-i+qsum(n)-qsum(pl); upd(pl,1); }else{ int pl=pr[i/2-1]; ans=pl-i+qsum(n)-qsum(pl); upd(pl,1); } } fans=min(fans,ans); } cout<<fans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 6 ms | 8276 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 6 ms | 8276 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 8 ms | 8360 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 6 ms | 8276 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |