Submission #110417

#TimeUsernameProblemLanguageResultExecution timeMemory
110417sofhiasouzaGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
0 / 100
3 ms384 KiB
#include <bits/stdc++.h> using namespace std; int n, cont; string s; inline int func(char x, char y) { queue < int > fila; if(s[0] != x) fila.push(0); for(int i = 1 ; i < s.size() ; i++) { if(s[i] == x and fila.size()) { cont += i - fila.front(); fila.pop(); s[i] = y; s[i-1] = x; } if(s[i] == s[i-1]) { if(x == s[i]) { fila.push(i); char aux = x; x = y; y = aux; } else fila.push(i); } } 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:11: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:40: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...