# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
930774 | Aiperiii | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 0 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
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;
}
char c1='G',c2='R';
if(cntR>cntG){
c1='R';c2='G';
}
if(s[0]=='R' && cntR==cntG){
c1='R';c2='G';
}
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++;
}
cout<<res<<"\n";
}
/*
8
1 10000
-1 -10000
2 0
-2 0
100 0
105 0
-100 0
-105 0
*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |