Submission #701384

#TimeUsernameProblemLanguageResultExecution timeMemory
701384BaytoroGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++17
100 / 100
63 ms163048 KiB
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define endl '\n' //#define int long long #define ll long long void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const ll INF=1e18,mod=1e9+7; const int N=405; vector<int> r,g,y; int p[N][3],dp[N][N][N][3]; void solve(){ int n;cin>>n; string s;cin>>s; for(int i=0;i<n;i++){ if(s[i]=='R') r.pb(i+1); if(s[i]=='G') g.pb(i+1); if(s[i]=='Y') y.pb(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<=(int)r.size();i++){ for(int j=0;j<=(int)g.size();j++){ for(int k=0;k<=(int)y.size();k++){ if(!i && !j && !k) continue; for(int l=0;l<3;l++) dp[i][j][k][l]=mod; int sum=i+j+k; if(i) dp[i][j][k][0]=min(dp[i-1][j][k][1],dp[i-1][j][k][2])+((r[i-1]+max(0,j-p[r[i-1]][1])+max(0,k-p[r[i-1]][2]))-sum); if(j) dp[i][j][k][1]=min(dp[i][j-1][k][0],dp[i][j-1][k][2])+((g[j-1]+max(0,i-p[g[j-1]][0])+max(0,k-p[g[j-1]][2]))-sum); if(k) dp[i][j][k][2]=min(dp[i][j][k-1][0],dp[i][j][k-1][1])+((y[k-1]+max(0,i-p[y[k-1]][0])+max(0,j-p[y[k-1]][1]))-sum); } } } int ans=*min_element(dp[r.size()][g.size()][y.size()],dp[r.size()][g.size()][y.size()]+3); if(ans>=mod) ans=-1; cout<<ans; } main(){ ios; int T=1; //cin>>T; while(T--){ solve(); } }

Compilation message (stderr)

joi2019_ho_t3.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      | ^~~~
joi2019_ho_t3.cpp: In function 'void fopn(std::string)':
joi2019_ho_t3.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...