Submission #110423

#TimeUsernameProblemLanguageResultExecution timeMemory
110423Leonardo_PaesGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++11
0 / 100
2 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; for(int i=0; i<s.size(); i++){ if(i%2==0 and s[i]=='B'){ for(int j=i; j<s.size(); j++){ if(i%2==1 and s[i]=='A'){ s[i]='A'; s[j]='B'; resp1+=j-i; break; } } if(s[i]=='B')res1=false; } else if(i%2==1 and s[i]=='A'){ for(int j=i; j<s.size(); j++){ if(j%2==0 and s[j]=='B'){ s[i]='B'; s[j]='A'; resp1+=j-i; break; } } if(s[i]=='A')res1=false; } } for(int i=0; i<s.size(); i++){ if(i%2==0 and s[i]=='A'){ for(int j=i; j<s.size(); j++){ if(i%2==1 and s[j]=='B'){ s[i]='B'; s[j]='A'; resp2+=j-i; break; } } if(s[i]=='A')res2=false; } else if(i%2==1 and s[i]=='B'){ for(int j=i; j<s.size(); j++){ if(i%2==1 and s[i]=='A'){ s[i]='A'; s[j]='B'; resp2+=j-i; break; } } if(s[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:24:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s.size(); i++){
                  ~^~~~~~~~~
joi2019_ho_t3.cpp:26:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=i; j<s.size(); j++){
                          ~^~~~~~~~~
joi2019_ho_t3.cpp:37:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=i; j<s.size(); j++){
                          ~^~~~~~~~~
joi2019_ho_t3.cpp:49:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s.size(); i++){
                  ~^~~~~~~~~
joi2019_ho_t3.cpp:51:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=i; j<s.size(); j++){
                          ~^~~~~~~~~
joi2019_ho_t3.cpp:62:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j=i; j<s.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...