Submission #884516

#TimeUsernameProblemLanguageResultExecution timeMemory
884516vjudge1Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
100 / 100
460 ms1017544 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define all(aa) aa.begin(), aa.end() const int INF=1e8; int n; vector<int> ind[3], cnt[3]; int dp[402][402][402][4]; int f(array<int, 3> x, int l){ if(x[0]+x[1]+x[2]==n) return 0; int &cur=dp[x[0]][x[1]][x[2]][l]; if(cur!=-1) return cur; cur=INF; for(int i=0; i<3; i++) if(i!=l && x[i]!=ind[i].size()){ int o=0, s=x[0]+x[1]+x[2]; for(int j=0; j<3; j++) if(j!=i) o+=max(0, x[j]-cnt[j][ind[i][x[i]]]); x[i]++; cur=min(cur, f(x, i)+o+ind[i][x[i]-1]-s); x[i]--; } return cur; } int main(){ string s; cin>>n>>s; for(int i=0; i<3; i++) cnt[i].resize(n); for(int i=0; i<n; i++){ if(i!=0){ for(int j=0; j<3; j++){ cnt[j][i]=cnt[j][i-1]; } } if(s[i]=='R'){ ind[0].push_back(i); cnt[0][i]++; } else if(s[i]=='G'){ ind[1].push_back(i); cnt[1][i]++; } else{ ind[2].push_back(i); cnt[2][i]++; } } memset(dp, -1, sizeof(dp)); int ans=f(array<int, 3>{0, 0, 0}, 3); cout<<(ans>=INF ? -1:ans)<<endl; }

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int f(std::array<int, 3>, int)':
joi2019_ho_t3.cpp:20:40: warning: comparison of integer expressions of different signedness: 'std::array<int, 3>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i=0; i<3; i++) if(i!=l && x[i]!=ind[i].size()){
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...