Submission #465152

#TimeUsernameProblemLanguageResultExecution timeMemory
465152ardaak33Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
1 ms204 KiB
#include <bits/stdc++.h> using namespace std; int sonuc=0; int sonuc2=0; int main() { int n; string s,bas; cin >> n; cin >> s; bas=s; int y=0,r=0,g=0; for (int i = 0; i < s.size(); i++) { if(s[i]=='Y') y++; else if(s[i]=='R') r++; else g++; } if((y-1>g+r) or (g-1>y+r) or (r-1>g+y)){ cout << "-1"; return 0; } for (int i = 1; i < s.size(); i++) { if(s[i] == s[i - 1]) { //cout << s[i] << s[i-1] << endl; char harf=s[i]; for (int j = i+1; j < s.size(); j++) { if(s[j]!=harf) { sonuc+=j-i; char temp = s[i]; s[i] = s[j]; s[j] = temp; break; } } } } bool bayrak=false; for (int i = 1; i < s.size(); i++) { if(s[i]==s[i-1]) bayrak = true; } if (bayrak) sonuc=INT_MAX; //sondan başla s=bas; for (int i = s.size()-2; i >= 0; i--) { if(s[i] == s[i + 1]) { //cout << s[i] << s[i+1] << endl; char harf=s[i]; for (int j = i-1; j >= 0; j--) { if(s[j]!=harf) { sonuc2+=i-j; char temp = s[i]; s[i] = s[j]; s[j] = temp; break; } } } } bool bayrak2=false; for (int i = 1; i < s.size(); i++) { if(s[i]==s[i-1]) bayrak2 = true; } if (bayrak2) sonuc2=INT_MAX; cout <<min(sonuc,sonuc2); } //GRRRGRGGRG //RGRGRGRGRG //3

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 | for (int i = 0; i < s.size(); i++)
      |                 ~~^~~~~~~~~~
joi2019_ho_t3.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 | for (int i = 1; i < s.size(); i++)
      |                 ~~^~~~~~~~~~
joi2019_ho_t3.cpp:36:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for (int j = i+1; j < s.size(); j++)
      |                           ~~^~~~~~~~~~
joi2019_ho_t3.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 | for (int i = 1; i < s.size(); i++)
      |                 ~~^~~~~~~~~~
joi2019_ho_t3.cpp:93:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 | for (int i = 1; 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...