Submission #896533

#TimeUsernameProblemLanguageResultExecution timeMemory
896533AndreyGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
15 / 100
199 ms754848 KiB
#include<bits/stdc++.h> using namespace std; vector<int> wut[3]; int dp[400][401][401][3]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; string s; cin >> s; vector<int> haha(n); for(int i = 0; i < n; i++) { if(s[i] == 'R') { haha[i] = 0; } else if(s[i] == 'G') { haha[i] = 1; } else { haha[i] = 2; } wut[haha[i]].push_back(i); } for(int i = 0; i < n; i++) { for(int j = 0; j <= wut[0].size(); j++) { for(int k = 0; k <= wut[1].size(); k++) { dp[i][j][k][0] = 1e9; dp[i][j][k][1] = 1e9; dp[i][j][k][2] = 1e9; if(j+k > i+1 || i+1-j-k > wut[2].size()) { continue; } int b = i+1-j-k; if(i > 0) { if(j != 0) { dp[i][j][k][0] = min(dp[i][j][k][0],min(dp[i-1][j-1][k][1],dp[i-1][j-1][k][2])+abs(i-wut[0][j-1])); } if(k != 0) { dp[i][j][k][1] = min(dp[i][j][k][1],min(dp[i-1][j][k-1][0],dp[i-1][j][k-1][2])+abs(i-wut[1][k-1])); } if(b != 0) { dp[i][j][k][2] = min(dp[i][j][k][2],min(dp[i-1][j][k][0],dp[i-1][j][k][1])+abs(i-wut[2][b-1])); } } else { if(j > 0) { dp[i][j][k][0] = abs(i-wut[0][0]); } if(k > 0) { dp[i][j][k][1] = abs(i-wut[1][0]); } if(b > 0) { dp[i][j][k][2] = abs(i-wut[2][0]); } } } } } int ans = dp[n-1][wut[0].size()][wut[1].size()][0]; ans = min(ans,dp[n-1][wut[0].size()][wut[1].size()][1]); ans = min(ans,dp[n-1][wut[0].size()][wut[1].size()][2]); if(ans >= (int)1e9) { cout << -1; } else { cout << ans/2; } return 0; }

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:31:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int j = 0; j <= wut[0].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:32:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             for(int k = 0; k <= wut[1].size(); k++) {
      |                            ~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:36:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |                 if(j+k > i+1 || i+1-j-k > wut[2].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...