Submission #1107327

#TimeUsernameProblemLanguageResultExecution timeMemory
1107327vjudge1Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
1 ms336 KiB
#include <bits/stdc++.h> using namespace std; void abb(){ int n, ans = 0; cin >> n; string s; cin >> s; int r = 0, g = 0, y = 0; for (int i = 0; i < s.size(); ++i){ if (s[i] == 'R') r++; else if (s[i] == 'G') g++; else y++; }if (r + g < y || y + g < r || r + y < g){ cout << "-1\n"; return; }for (int i = 0; i < s.size(); ++i){ if (s[i] == s[i + 1]){ int j = i + 1; while(j < s.size() && s[j] == s[i]) j++; // cout << j << " " << i << " " << s[i] << " " << s[j] << "\n"; swap(s[i + 1], s[j]); ans += j - i - 1; } }cout << ans << "\n"; } signed main(){ int T = 1; // cin >> T; while(T--){ abb(); } } // 5 6 // - - - - - - // - - - - - - // - - - - - - // - - + + + + // + + + + - -

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'void abb()':
joi2019_ho_t3.cpp:9:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int i = 0; i < s.size(); ++i){
      |                     ~~^~~~~~~~~~
joi2019_ho_t3.cpp:15:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     }for (int i = 0; i < s.size(); ++i){
      |                      ~~^~~~~~~~~~
joi2019_ho_t3.cpp:18:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |             while(j < s.size() && s[j] == s[i]) j++;
      |                   ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...