답안 #930775

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930775 2024-02-20T11:57:31 Z Aiperiii Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
15 / 100
1 ms 432 KB
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
int calc(char c1,char c2,string s){
    int n=s.size();
    int cnt=0,res=0;
    for(int i=0;i<n;i++){
        if(cnt%2==0){
            if(s[i]!=c1){
                s[i]=c1;
                for(int j=i+1;j<n;j++){
                    if(s[j]==c1){
                        s[j]=c2;
                        res+=j-i;
                        break;
                    }
                }
            }
        }
        else{
            if(s[i]!=c2){
                s[i]=c2;
                for(int j=i+1;j<n;j++){
                    if(s[j]==c2){
                        s[j]=c1;
                        res+=j-i;
                        break;
                    }
                }
            }
        }
        cnt++;
    }
    return res;
}
signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cntR=0,cntG=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='R')cntR++;
        else cntG++;
    }
    if(abs(cntR-cntG)>1){
        cout<<-1;
        return 0;
    }
    if(cntR>cntG){
        cout<<calc('R','G',s)<<"\n";
    }
    else if(cntR<cntG){
        cout<<calc('G','R',s)<<"\n";
    }
    if(cntR==cntG){
        cout<<min(calc('G','R',s),calc('R','G',s))<<"\n";
    }
    
}
/*

 */

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:48:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 424 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 432 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 432 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -