답안 #465152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465152 2021-08-15T09:15:00 Z ardaak33 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
1 ms 204 KB
#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

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++)
      |                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -