Submission #465147

# Submission time Handle Problem Language Result Execution time Memory
465147 2021-08-15T09:04:37 Z ardaak33 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
0 ms 204 KB
#include <bits/stdc++.h>
using namespace std;
int sonuc=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)
{
  cout <<sonuc;
  return 0;
}

//sondan başla
sonuc=0;
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)
            {
                sonuc+=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)
{
  cout <<sonuc;
  return 0;
}






}
//
//

Compilation message

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:94:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 | for (int i = 1; i < s.size(); i++)
      |                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -