| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 377958 | astoria | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 1 ms | 364 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
int mn(int x, int y){
if(x!=-1&&y!=-1) return min(x,y);
else if(x!=-1) return x;
else return y;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n; cin>>n;
string s; int a[n+5];
cin>>s;
s='0'+s;
int ct[2]; memset(ct,0,sizeof(ct));
vector<int> p[2];
for(int i=1; i<=n; i++){
if(s[i]=='R') a[i]=0;
else a[i]=1;
ct[a[i]]++;
p[a[i]].push_back(i);
}
if(abs(ct[0]-ct[1]) > 1){ cout<<-1; return 0;}
int dp[n+5][2]; memset(dp,-1,sizeof(dp));
dp[1][a[1]] = 0;
if(a[1]==0){
int fs;
for(int i=2; i<=n; i++){
if(a[i]==1){ fs=i; break;}
}
dp[1][1] = fs-1;
}
else{
int fs;
for(int i=2; i<=n; i++){
if(a[i]==0){ fs=i; break;}
}
dp[1][0] = fs-1;
}
for(int i=2; i<=n; i++){
for(int j=0; j<=1; j++){
int num[2];
num[j] = (n+1)/2;
num[!j] = n/2;
for(int k=0; k<=1; k++){
int crp;
if(k==a[i-1]) crp=a[i-1];
else crp=a[i];
if(crp==j) dp[i][j] = mn(dp[i][j],dp[i-1][k]);
else{
dp[i][j] = mn(dp[i][j], dp[i-1][k] + p[j][num[j]]-i);
}
}
}
}
if(ct[0]>ct[1]) cout<<dp[n][0];
else if(ct[1]>ct[0]) cout<<dp[n][1];
else cout<<mn(dp[n][0],dp[n][1]);
}
컴파일 시 표준 에러 (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... | ||||
