# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110428 | 2019-05-10T20:26:37 Z | pamaj | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 3 ms | 300 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 410; int n; bool check(vector<pair<char, int>> &t) { for(int i = 0; i < t.size() - 1; i++) if(t[i].first == t[i + 1].first) return false; return true; } void next_try(string &t) { for(int p = t.size() - 1; p > 0; p--) { swap(t[p], t[p - 1]); } } int qt[4]; int main() { cin >> n; vector<char> s, t; for(int i = 0; i < n; i++) { char c; cin >> c; int tipo; if(c == 'R') tipo = 1; else if(c == 'G') tipo = 2; else tipo = 3; qt[tipo]++; s.push_back(c); } string crct; int metade = n/2 + (n % 2 == 1); if(qt[1] > metade or qt[2] > metade or qt[3] > metade) { cout << -1 << "\n"; return 0; } int cont = 0; vector<char> ch[3]; for(int i = 0; i < qt[1]; i++) ch[0].push_back('R'); for(int i = 0; i < qt[2]; i++) ch[1].push_back('G'); for(int i = 0; i < qt[3]; i++) ch[2].push_back('Y'); for(int i = 0; i < n; i++) { while((int)ch[cont].size() == 0) cont++, cont %= 3; crct += ch[cont][0]; ch[cont].pop_back(); cont++; cont %= 3; } //cout << crct << "\n"; int ans = 1e9; for(int j = 0; j < n; j++) { next_try(crct); //cout << crct << "\n"; vector<int> v1r, v1g, v1y; vector<int> v2r, v2g, v2y; for(int i = 0; i < n; i++) { if(s[i] == 'R') { v1r.push_back(i); } if(s[i] == 'G') { v1g.push_back(i); } if(s[i] == 'Y') { v1y.push_back(i); } if(crct[i] == 'R') { v2r.push_back(i); } if(crct[i] == 'G') { v2g.push_back(i); } if(crct[i] == 'Y') { v2y.push_back(i); } } int num_dif = 0; for(int i = 0; i < v1y.size(); i++) { num_dif += abs(v1y[i] - v2y[i]); } for(int i = 0; i < v1r.size(); i++) { num_dif += abs(v1r[i] - v2r[i]); } for(int i = 0; i < v1g.size(); i++) { num_dif += abs(v1g[i] - v2g[i]); } ans = min(ans, num_dif/2); } cout << (ans == (int)1e9 ? -1 : ans) << "\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 3 ms | 300 KB | Output is correct |
4 | Incorrect | 2 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 3 ms | 300 KB | Output is correct |
4 | Incorrect | 2 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 256 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 3 ms | 300 KB | Output is correct |
4 | Incorrect | 2 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |