Submission #1102049

#TimeUsernameProblemLanguageResultExecution timeMemory
1102049hqminhuwuGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
100 / 100
134 ms780468 KiB
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef long double ld; typedef pair <ll,ll> pll; typedef pair <int,int> pii; typedef pair <int,pii> piii; #define forr(_a,_b,_c) for(int _a = (_b); _a <= int (_c); ++_a) #define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> int (_c);) #define forf(_a,_b,_c) for(int _a = (_b); _a < int (_c); ++_a) #define st first #define nd second #define pb push_back #define mp make_pair #define all(x) begin(x),end(x) #define mask(i) (1LL << (i)) #define bit(x, i) (((x) >> (i)) & 1) #define bp __builtin_popcountll #define file "test" template<class X, class Y> bool minz(X &x, const Y &y) { if (x > y) { x = y; return true; } return false; } template<class X, class Y> bool maxz(X &x, const Y &y) { if (x < y) { x = y; return true; } return false; } const int N = 4e2 + 5; const ll oo = (ll) 1e16; const ll mod = 1e9 + 7; // 998244353; string w = "GRY"; string s; int dp[N][N][N][3], n, pre[N][3]; vector <int> pos[3]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef kaguya freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout); #endif cin >> n >> s; memset (dp, 63, sizeof dp); dp[0][0][0][1] = dp[0][0][0][2] = dp[0][0][0][0] = 0; forr (i, 1, n){ forr (j, 0, 2){ pre[i][j] = pre[i - 1][j]; if (s[i - 1] == w[j]){ pos[j].pb(i); pre[i][j]++; } } } forr (i, 0, pos[0].size()){ forr (j, 0, pos[1].size()){ forr (k, 0, pos[2].size()){ forr (t, 0, 2) if(dp[i][j][k][t] < mod){ if (t != 0 && i < pos[0].size()){ int tmp1 = max(pre[pos[0][i]][1] - j, 0); int tmp2 = max(pre[pos[0][i]][2] - k, 0); minz(dp[i + 1][j][k][0], dp[i][j][k][t] + tmp1 + tmp2); } if (t != 1 && j < pos[1].size()){ int tmp1 = max(pre[pos[1][j]][0] - i, 0); int tmp2 = max(pre[pos[1][j]][2] - k, 0); minz(dp[i][j + 1][k][1], dp[i][j][k][t] + tmp1 + tmp2); } if(t != 2 && k < pos[2].size()){ int tmp1 = max(pre[pos[2][k]][0] - i, 0); int tmp2 = max(pre[pos[2][k]][1] - j, 0); minz(dp[i][j][k + 1][2], dp[i][j][k][t] + tmp1 + tmp2); } } } } } int res = mod; forr (t, 0, 2){ minz(res, dp[pos[0].size()][pos[1].size()][pos[2].size()][t]); } cout << (res == mod ? -1 : res) << "\n"; return 0; } /* */

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:74:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |                     if (t != 0 && i < pos[0].size()){
      |                                   ~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:80:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |                     if (t != 1 && j < pos[1].size()){
      |                                   ~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:86:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |                     if(t != 2 && k < pos[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...