# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
927862 | 2024-02-15T12:18:07 Z | Unforgettablepl | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 1 ms | 460 KB |
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = 1e15; int calc(vector<bool> arr,bool start){ arr.insert(arr.begin(),start); int ans = 0; for(int i=1;i<arr.size();i++){ int idx = find(arr.begin()+i, arr.end(),!arr[i-1])-arr.begin(); ans+=idx-i; arr.erase(arr.begin()+idx); arr.insert(arr.begin()+i,!arr[i-1]); } return ans; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int red = 0; int green = 0; vector<bool> arr; for(int i=1;i<=n;i++){ char a; cin>>a; if(a=='R') { red++; arr.emplace_back(true);} else {green++;arr.emplace_back(false);} } if(abs(red-green)>1){ cout << "-1\n"; return 0; } int ans = INF; if(red<=green)ans=min(ans, calc(arr,true)); if(green<=red)ans=min(ans, calc(arr,false)); cout << ans << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 460 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 1 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 344 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |