# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
781743 | 2023-07-13T10:32:05 Z | vjudge1 | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 1 ms | 320 KB |
#include <bits/stdc++.h> using namespace std; #define int long long #define faster ios_base::sync_with_stdio(false);cin.tie(NULL); #define OYY 1000000005 #define mod 998244353 #define mid (start+end)/2 vector <int> v,v2; int32_t main(){ faster int n;cin>>n; int r=0,g=0,sr=0,sg=0; string s;cin>>s; for(int i=0;i<n;i++){ if(s[i]=='R')sr++; else sg++; } //////////////////////////// if(n%2==0 && (sr!=sg)){ cout<<-1<<'\n'; return 0; } if(n%2==1 && !(sr+1==sg || sg+1==sr)){ cout<<-1<<'\n'; return 0; } for(int i=0;i<n;i++){ if(s[i]=='R'){ v.push_back(i); } else v2.push_back(i); } ///////////////////////////////// int cev=0; for(int i=0;i<min(v.size(),v2.size());i++){ cev+=abs(v[i]-v2[i])-1; } if(n%2==0)cout<<cev<<'\n'; else{ if(sr<sg){ if(s[0]=='G' && s[n-1]=='G')cout<<cev<<'\n'; else cout<<cev+1<<'\n'; } else{ if(s[0]=='R' && s[n-1]=='R')cout<<cev<<'\n'; else cout<<cev+1<<'\n'; } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 320 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Incorrect | 1 ms | 320 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 320 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Incorrect | 1 ms | 320 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 316 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 320 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Incorrect | 1 ms | 320 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |