답안 #208647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208647 2020-03-12T01:15:11 Z YJU Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
26 ms 13432 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll N=65;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll R,G,Y;
ll n,dp[N][N][N][3],p[N][3];
string s;
vector<ll> v[3];

ll f(ll id,ll ty,ll ha){
	return max(0LL,ha-p[id][ty]);
}

int main(){
	//ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>s;
	REP(i,SZ(s))(s[i]=='R'?v[0]:(s[i]=='G'?v[1]:v[2])).pb(i),(s[i]=='R'?R:(s[i]=='G'?G:Y))++;
	REP(i,n){
		REP(ty,3)p[i][ty]=(i?p[i-1][ty]:0LL);
		(s[i]=='R'?p[i][0]:(s[i]=='G'?p[i][1]:p[i][2]))++;
	}
	REP(i,N)REP(j,N)REP(k,N)REP(ty,3)dp[i][j][k][ty]=(1LL<<60);
	dp[0][0][0][0]=dp[0][0][0][1]=dp[0][0][0][2]=0;
	REP(i,n+1){
		REP(j,G+1){
			REP(k,Y+1){
				if(k+j>i||i-j-k>R)continue;
				REP(ty,3){
					//cout<<i<<" "<<j<<" "<<k<<" "<<ty<<"::"<<dp[i][j][k][ty]<<"\n";
					ll x=i-j-k;
					if(ty!=0&&x<R)dp[i+1][j][k][0]=min(dp[i+1][j][k][0],dp[i][j][k][ty]+(v[0][x]+f(v[0][x],1,j)+f(v[0][x],2,k)-i));
					if(ty!=1&&j<G)dp[i+1][j+1][k][1]=min(dp[i+1][j+1][k][1],dp[i][j][k][ty]+(v[1][j]+f(v[1][j],0,x)+f(v[1][j],2,k)-i));
					if(ty!=2&&k<Y)dp[i+1][j][k+1][2]=min(dp[i+1][j][k+1][2],dp[i][j][k][ty]+(v[2][k]+f(v[2][k],0,x)+f(v[2][k],1,j)-i));
				}
			}
		}
	}
	ll ans=min(dp[n][G][Y][0],min(dp[n][G][Y][1],dp[n][G][Y][2]));
	cout<<ans<<"\n";
	return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6776 KB Output is correct
2 Correct 8 ms 6776 KB Output is correct
3 Correct 9 ms 6776 KB Output is correct
4 Correct 8 ms 6776 KB Output is correct
5 Correct 8 ms 6776 KB Output is correct
6 Correct 8 ms 6776 KB Output is correct
7 Correct 8 ms 6776 KB Output is correct
8 Correct 8 ms 6780 KB Output is correct
9 Correct 8 ms 6776 KB Output is correct
10 Incorrect 8 ms 6776 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6776 KB Output is correct
2 Correct 8 ms 6776 KB Output is correct
3 Correct 9 ms 6776 KB Output is correct
4 Correct 8 ms 6776 KB Output is correct
5 Correct 8 ms 6776 KB Output is correct
6 Correct 8 ms 6776 KB Output is correct
7 Correct 8 ms 6776 KB Output is correct
8 Correct 8 ms 6780 KB Output is correct
9 Correct 8 ms 6776 KB Output is correct
10 Incorrect 8 ms 6776 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6776 KB Output is correct
2 Runtime error 26 ms 13432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6776 KB Output is correct
2 Correct 8 ms 6776 KB Output is correct
3 Correct 9 ms 6776 KB Output is correct
4 Correct 8 ms 6776 KB Output is correct
5 Correct 8 ms 6776 KB Output is correct
6 Correct 8 ms 6776 KB Output is correct
7 Correct 8 ms 6776 KB Output is correct
8 Correct 8 ms 6780 KB Output is correct
9 Correct 8 ms 6776 KB Output is correct
10 Incorrect 8 ms 6776 KB Output isn't correct
11 Halted 0 ms 0 KB -