# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
927862 | Unforgettablepl | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 1 ms | 460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e15;
int calc(vector<bool> arr,bool start){
arr.insert(arr.begin(),start);
int ans = 0;
for(int i=1;i<arr.size();i++){
int idx = find(arr.begin()+i, arr.end(),!arr[i-1])-arr.begin();
ans+=idx-i;
arr.erase(arr.begin()+idx);
arr.insert(arr.begin()+i,!arr[i-1]);
}
return ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int red = 0;
int green = 0;
vector<bool> arr;
for(int i=1;i<=n;i++){
char a;
cin>>a;
if(a=='R') { red++; arr.emplace_back(true);}
else {green++;arr.emplace_back(false);}
}
if(abs(red-green)>1){
cout << "-1\n";
return 0;
}
int ans = INF;
if(red<=green)ans=min(ans, calc(arr,true));
if(green<=red)ans=min(ans, calc(arr,false));
cout << ans << '\n';
}
컴파일 시 표준 에러 (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... |