# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
217309 | 2020-03-29T11:50:53 Z | kshitij_sodani | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 500 ms | 755808 KB |
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long int llo; #define mp make_pair #define pb push_back #define a first #define b second #define endl "\n" llo mod=1000000007; int n; int it[401]; int dp[401][401][401][3]; vector<int> aa; vector<int> bb; vector<int> cc; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; char ss; int co=0; int co2=0; for(int i=0;i<n;i++){ for(int j=0;j<=n;j++){ for(int k=0;k<=n;k++){ for(int l=0;l<3;l++){ dp[i][j][k][l]=400000; } } } } int pre[n][3]; for(int i=0;i<n;i++){ if(i==0){ pre[i][0]=0; pre[i][1]=0; pre[i][2]=0; } else{ pre[i][0]=pre[i-1][0]; pre[i][1]=pre[i-1][1]; pre[i][2]=pre[i-1][2]; } cin>>ss; if(ss=='R'){ co+=1; aa.pb(i); pre[i][0]+=1; } else if(ss=='G'){ it[i]=1; co2+=1; pre[i][1]+=1; bb.pb(i); } else{ pre[i][2]+=1; cc.pb(i); } } if(co>(n+1)/2 or co2>(n+1)/2 or (n-co-co2)>(n+1)/2){ cout<<-1<<endl; return 0; } for(int i=0;i<n;i++){ for(int j=0;j<=n;j++){ for(int k=0;k<=n;k++){ if((i+1)-j-k>(i+2)/2 or j>(i+2)/2 or k>(i+2)/2 or j+k>i+1){ continue; } if(j>0 and j<=aa.size()){ if(i>0){ dp[i][j][k][0]=abs(pre[i][1]-pre[aa[j-1]][1])+abs(pre[i][2]-pre[aa[j-1]][2])+min(dp[i-1][j-1][k][1],dp[i-1][j-1][k][2]); } else{ dp[i][j][k][0]=abs(pre[i][1]-pre[aa[j-1]][1])+abs(pre[i][2]-pre[aa[j-1]][2]); } } if(k>0 and k<=bb.size()){ if(i>0){ dp[i][j][k][1]=abs(pre[i][0]-pre[bb[k-1]][0])+abs(pre[i][2]-pre[bb[k-1]][2])+min(dp[i-1][j][k-1][0],dp[i-1][j][k-1][2]); } else{ dp[i][j][k][1]=abs(pre[i][0]-pre[bb[k-1]][0])+abs(pre[i][2]-pre[bb[k-1]][2]); } } if(j+k<i+1 and i+1-j-k<=cc.size()){ if(i>0){ dp[i][j][k][2]=abs(pre[i][0]-pre[cc[i-j-k]][0])+abs(pre[i][1]-pre[cc[i-j-k]][1])+min(dp[i-1][j][k][0],dp[i-1][j][k][1]); } else{ dp[i][j][k][2]=abs(pre[i][0]-pre[cc[i-j-k]][0])+abs(pre[i][1]-pre[cc[i-j-k]][1]); } } // cout<<dp[i][j][k][0]<<","<<dp[i][j][k][1]<<","<<dp[i][j][k][2]<<endl; } } } int mi=400000; for(int j=0;j<=3;j++){ mi=min(mi,dp[n-1][aa.size()][bb.size()][j]); } if(mi>=400000){ while(true){ continue; } } cout<<mi<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 768 KB | Output is correct |
5 | Incorrect | 5 ms | 1408 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 768 KB | Output is correct |
5 | Incorrect | 5 ms | 1408 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 478 ms | 755808 KB | Output is correct |
3 | Correct | 473 ms | 753400 KB | Output is correct |
4 | Correct | 495 ms | 755576 KB | Output is correct |
5 | Correct | 496 ms | 755732 KB | Output is correct |
6 | Correct | 479 ms | 755576 KB | Output is correct |
7 | Execution timed out | 517 ms | 753436 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 4 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 768 KB | Output is correct |
5 | Incorrect | 5 ms | 1408 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |