# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
884516 | vjudge1 | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 460 ms | 1017544 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define all(aa) aa.begin(), aa.end()
const int INF=1e8;
int n;
vector<int> ind[3], cnt[3];
int dp[402][402][402][4];
int f(array<int, 3> x, int l){
if(x[0]+x[1]+x[2]==n) return 0;
int &cur=dp[x[0]][x[1]][x[2]][l];
if(cur!=-1) return cur;
cur=INF;
for(int i=0; i<3; i++) if(i!=l && x[i]!=ind[i].size()){
int o=0, s=x[0]+x[1]+x[2];
for(int j=0; j<3; j++) if(j!=i)
o+=max(0, x[j]-cnt[j][ind[i][x[i]]]);
x[i]++;
cur=min(cur, f(x, i)+o+ind[i][x[i]-1]-s);
x[i]--;
}
return cur;
}
int main(){
string s;
cin>>n>>s;
for(int i=0; i<3; i++) cnt[i].resize(n);
for(int i=0; i<n; i++){
if(i!=0){
for(int j=0; j<3; j++){
cnt[j][i]=cnt[j][i-1];
}
}
if(s[i]=='R'){
ind[0].push_back(i);
cnt[0][i]++;
}
else if(s[i]=='G'){
ind[1].push_back(i);
cnt[1][i]++;
}
else{
ind[2].push_back(i);
cnt[2][i]++;
}
}
memset(dp, -1, sizeof(dp));
int ans=f(array<int, 3>{0, 0, 0}, 3);
cout<<(ans>=INF ? -1:ans)<<endl;
}
컴파일 시 표준 에러 (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... |