Submission #110427

#TimeUsernameProblemLanguageResultExecution timeMemory
110427Leonardo_PaesGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++11
15 / 100
3 ms384 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; string s; cin >> s; int resp1=0, resp2=0; int r=0, g=0; for(int i=0; i<s.size(); i++){ if(s[i]=='R')s[i]='A'; else s[i]='B'; } bool res1=true, res2=true; string s1=s, s2=s; for(int i=0; i<s1.size(); i++){ if(i%2==0 and s1[i]=='B'){ for(int j=i; j<s1.size(); j++){ if(j%2==1 and s1[j]=='A'){ s1[i]='A'; s1[j]='B'; resp1+=j-i; break; } } if(s1[i]=='B')res1=false; } else if(i%2==1 and s1[i]=='A'){ for(int j=i; j<s1.size(); j++){ if(j%2==0 and s1[j]=='B'){ s1[i]='B'; s1[j]='A'; resp1+=j-i; break; } } if(s1[i]=='A')res1=false; } } for(int i=0; i<s2.size(); i++){ if(i%2==0 and s2[i]=='A'){ for(int j=i; j<s2.size(); j++){ if(j%2==1 and s2[j]=='B'){ s2[i]='B'; s2[j]='A'; resp2+=j-i; break; } } if(s2[i]=='A')res2=false; } else if(i%2==1 and s2[i]=='B'){ for(int j=i; j<s2.size(); j++){ if(j%2==0 and s2[j]=='A'){ s2[i]='A'; s2[j]='B'; resp2+=j-i; break; } } if(s2[i]=='B')res2=false; } } if(res1==true and res2==true){ cout << min(resp1, resp2) << endl; } else if(res1==true){ cout << resp1 << endl; } else if(res2==true){ cout << resp2 << endl; } else{ cout << -1 << endl; } return 0; }

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:19:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s.size(); i++){
                  ~^~~~~~~~~
joi2019_ho_t3.cpp:27:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s1.size(); i++){
                  ~^~~~~~~~~~
joi2019_ho_t3.cpp:29:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=i; j<s1.size(); j++){
                          ~^~~~~~~~~~
joi2019_ho_t3.cpp:40:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=i; j<s1.size(); j++){
                          ~^~~~~~~~~~
joi2019_ho_t3.cpp:52:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s2.size(); i++){
                  ~^~~~~~~~~~
joi2019_ho_t3.cpp:54:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=i; j<s2.size(); j++){
                          ~^~~~~~~~~~
joi2019_ho_t3.cpp:65:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=i; j<s2.size(); j++){
                          ~^~~~~~~~~~
joi2019_ho_t3.cpp:17:9: warning: unused variable 'r' [-Wunused-variable]
     int r=0, g=0;
         ^
joi2019_ho_t3.cpp:17:14: warning: unused variable 'g' [-Wunused-variable]
     int r=0, g=0;
              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...