Submission #110429

#TimeUsernameProblemLanguageResultExecution timeMemory
110429sofhiasouzaGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
0 / 100
3 ms384 KiB
#include <bits/stdc++.h> using namespace std; int n, cont = 0; string s; inline int func(char x, char y) { queue < int > fila; if(s[0] != x) fila.push(0); s[0] = x; for(int i = 1 ; i < s.size() ; i++) { if(s[i] == x and fila.size()) { //cout << i << ' ' << x << ' ' << fila.size() << ' ' << fila.front() << endl; cont += i - fila.front(); fila.pop(); s[i] = y; } if(s[i] == s[i-1]) { if(x == s[i]) { s[i] = y; fila.push(i); char aux = x; x = y; y = aux; } else { fila.push(i); s[i] = x; } } } if(fila.size()) return -1; return cont; } int main() { cin >> n; cin >> s; int r = 0, g = 0; for(int i = 0 ; i < s.size() ; i++) { if(s[i] == 'R') r++; else g++; } if(r > g+1 or g > r+1) cout << -1 << endl; else { if(r > g) cout << func('R', 'G') << endl; else if(g > r) cout << func('G', 'R') << endl; else cout << func(s[0], s[0] == 'G' ? 'R' : 'G') << endl; } }

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int func(char, char)':
joi2019_ho_t3.cpp:12:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1 ; i < s.size() ; i++)
                  ~~^~~~~~~~~~
joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0 ; i < s.size() ; i++)
                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...