| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1120041 | AndrijaM | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 119 ms | 164876 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
///#define endl '\n'
const int maxn=400+10;
int dp[maxn][maxn][maxn][3];/// red,green,yellow and what is the last color
int p[maxn][3];
signed main()
{
///freopen("detonator.in","r",stdin);
///freopen("detonator.out","w",stdout);
ios::sync_with_stdio(false);
int n;
cin>>n;
string s;
cin>>s;
vector<int>r;
vector<int>g;
vector<int>y;
for(int i=0;i<n;i++)
{
if(s[i]=='R')
{
r.push_back(i+1);
}
if(s[i]=='G')
{
g.push_back(i+1);
}
if(s[i]=='Y')
{
y.push_back(i+1);
}
p[i+1][0]=r.size();
p[i+1][1]=g.size();
p[i+1][2]=y.size();
}
for(int i=0;i<=r.size();i++)
{
for(int j=0;j<=g.size();j++)
{
for(int k=0;k<=y.size();k++)
{
if(i==0 && j==0 && k==0)continue;
for(int idx=0;idx<3;idx++)
{
dp[i][j][k][idx]=1e9;
}
int s=i+k+j;
if(i!=0)
{
dp[i][j][k][0]=min(dp[i-1][j][k][1],dp[i-1][j][k][2])+((r[i-1]+max(0LL,j-p[r[i-1]][1])+max(0LL,k-p[r[i-1]][2]))-s);
}
if(j!=0)
{
dp[i][j][k][1]=min(dp[i][j-1][k][0],dp[i][j-1][k][2])+((g[j-1]+max(0LL,i-p[g[j-1]][0])+max(0LL,k-p[g[j-1]][2]))-s);
}
if(k!=0)
{
dp[i][j][k][2]=min(dp[i][j][k-1][0],dp[i][j][k-1][1])+((y[k-1]+max(0LL,i-p[y[k-1]][0])+max(0LL,j-p[y[k-1]][1]))-s);
}
}
}
}
int ans = *min_element(dp[r.size()][g.size()][y.size()], dp[r.size()][g.size()][y.size()] + 3);
if(ans>=1e9)
{
cout<<-1<<endl;
}
else
{
cout<<ans<<endl;
}
return 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... | ||||
