답안 #781739

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781739 2023-07-13T10:30:56 Z vjudge1 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);
#define OYY 1000000005
#define mod 998244353
#define mid (start+end)/2
vector <int> v,v2;

int32_t main(){
    faster
    int n;cin>>n;
    int r=0,g=0,sr=0,sg=0;
    string s;cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='R')sr++;
        else sg++;
    }
    ////////////////////////////
    if(n%2==0 && (sr!=sg)){
        cout<<-1<<'\n';
        return 0;
    }
    if(n%2==1 && !(sr+1==sg || sg+1==sr)){
        cout<<-1<<'\n';
        return 0;
    }
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            v.push_back(i);
        }
        else v2.push_back(i);
    }
    /////////////////////////////////
    int cev=0;

    for(int i=0;i<min(v.size(),v2.size());i++){
        cev+=abs(v[i]-v2[i])-1;
    }
    if(n%2==0)cout<<cev<<'\n';
    else{
        if(sr<sg){
            if(s[0]=='G')cout<<cev<<'\n';
            else cout<<cev+1<<'\n';
        }
        else{
            if(s[0]=='R')cout<<cev<<'\n';
            else cout<<cev+1<<'\n';

        }
    }

    return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int32_t main()':
joi2019_ho_t3.cpp:37:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'const long unsigned int' [-Wsign-compare]
   37 |     for(int i=0;i<min(v.size(),v2.size());i++){
      |                 ~^~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:13:9: warning: unused variable 'r' [-Wunused-variable]
   13 |     int r=0,g=0,sr=0,sg=0;
      |         ^
joi2019_ho_t3.cpp:13:13: warning: unused variable 'g' [-Wunused-variable]
   13 |     int r=0,g=0,sr=0,sg=0;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -