Submission #1087628

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
10876282024-09-13 03:21:15efishelGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++17
75 / 100
1088 ms769108 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
vll ou[3];
int dp[403][403][403][3]; // dp[a][b][c][last] = min operations to have a valid string\
rn having a prefix of length a+b+c having taken a as, b bs, and c cs, having the last color as last
int fposi (ll a, ll b, ll c, ll i) {
int pos = i;
for (ll j = 0; j < a; j++) if (ou[0][j] > i) pos++;
for (ll j = 0; j < b; j++) if (ou[1][j] > i) pos++;
for (ll j = 0; j < c; j++) if (ou[2][j] > i) pos++;
return pos;
}
ll n;
int solve (ll a, ll b, ll c, ll last) { // have taken the first a as b bs and c cs, the last rn is last
if (a+b+c == n) return 0;
if (dp[a][b][c][last] <= 1e9) return dp[a][b][c][last];
int &ans = dp[a][b][c][last];
ans = 1e9;
int i = a+b+c;
if (last != 0 && a < ou[0].size()) { ans = min(ans, solve(a+1, b, c, 0) + fposi(a, b, c, ou[0][a])-i); }
if (last != 1 && b < ou[1].size()) { ans = min(ans, solve(a, b+1, c, 1) + fposi(a, b, c, ou[1][b])-i); }
if (last != 2 && c < ou[2].size()) { ans = min(ans, solve(a, b, c+1, 2) + fposi(a, b, c, ou[2][c])-i); }
return ans;
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Compilation message (stderr)

joi2019_ho_t3.cpp:7:27: warning: multi-line comment [-Wcomment]
    7 | int dp[403][403][403][3]; // dp[a][b][c][last] = min operations to have a valid string\
      |                           ^
joi2019_ho_t3.cpp: In function 'int solve(ll, ll, ll, ll)':
joi2019_ho_t3.cpp:25:24: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     if (last != 0 && a < ou[0].size()) { ans = min(ans, solve(a+1, b, c, 0) + fposi(a, b, c, ou[0][a])-i); }
      |                      ~~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:26:24: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     if (last != 1 && b < ou[1].size()) { ans = min(ans, solve(a, b+1, c, 1) + fposi(a, b, c, ou[1][b])-i); }
      |                      ~~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:27:24: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     if (last != 2 && c < ou[2].size()) { ans = min(ans, solve(a, b, c+1, 2) + fposi(a, b, c, ou[2][c])-i); }
      |                      ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...