Submission #208647

#TimeUsernameProblemLanguageResultExecution timeMemory
208647YJUGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
0 / 100
26 ms13432 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...