#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;
typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements
#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));
int n,memo[405][405][405][3];
char c;
vi v[3];
int dp(int i,int j,int k,int pv){
int p=i+j+k;
if(p==n)return 0;
if(p!=0&&memo[i][j][k][pv]!=-1)return memo[i][j][k][pv];
int res=INF;
if(pv!=0&&i<sz(v[0]))mnto(res,dp(i+1,j,k,0)+max(0,v[0][i]-p));
if(pv!=1&&j<sz(v[1]))mnto(res,dp(i,j+1,k,1)+max(0,v[1][j]-p));
if(pv!=2&&k<sz(v[2]))mnto(res,dp(i,j,k+1,2)+max(0,v[2][k]-p));
return memo[i][j][k][pv]=res;
}
int main(){
sf("%d",&n);
for(int i=0;i<n;++i){
sf(" %c",&c);
if(c=='R')v[0].pb(i);
if(c=='G')v[1].pb(i);
if(c=='Y')v[2].pb(i);
}
memset(memo,-1,sizeof memo);
int ans=dp(0,0,0,-1);
if(ans==INF)ans=-1;
pf("%d\n",ans);
}
Compilation message
joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:56:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | sf("%d",&n);
| ^
joi2019_ho_t3.cpp:58:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | sf(" %c",&c);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
396 ms |
780252 KB |
Output is correct |
2 |
Correct |
376 ms |
780348 KB |
Output is correct |
3 |
Correct |
378 ms |
780236 KB |
Output is correct |
4 |
Correct |
390 ms |
780196 KB |
Output is correct |
5 |
Correct |
390 ms |
780268 KB |
Output is correct |
6 |
Correct |
381 ms |
780240 KB |
Output is correct |
7 |
Correct |
384 ms |
780268 KB |
Output is correct |
8 |
Correct |
400 ms |
780284 KB |
Output is correct |
9 |
Correct |
378 ms |
780208 KB |
Output is correct |
10 |
Correct |
376 ms |
780168 KB |
Output is correct |
11 |
Incorrect |
395 ms |
780244 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
396 ms |
780252 KB |
Output is correct |
2 |
Correct |
376 ms |
780348 KB |
Output is correct |
3 |
Correct |
378 ms |
780236 KB |
Output is correct |
4 |
Correct |
390 ms |
780196 KB |
Output is correct |
5 |
Correct |
390 ms |
780268 KB |
Output is correct |
6 |
Correct |
381 ms |
780240 KB |
Output is correct |
7 |
Correct |
384 ms |
780268 KB |
Output is correct |
8 |
Correct |
400 ms |
780284 KB |
Output is correct |
9 |
Correct |
378 ms |
780208 KB |
Output is correct |
10 |
Correct |
376 ms |
780168 KB |
Output is correct |
11 |
Incorrect |
395 ms |
780244 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
380 ms |
780164 KB |
Output is correct |
2 |
Correct |
369 ms |
780320 KB |
Output is correct |
3 |
Correct |
368 ms |
780324 KB |
Output is correct |
4 |
Correct |
374 ms |
780252 KB |
Output is correct |
5 |
Correct |
375 ms |
780296 KB |
Output is correct |
6 |
Correct |
399 ms |
780228 KB |
Output is correct |
7 |
Correct |
385 ms |
780220 KB |
Output is correct |
8 |
Correct |
384 ms |
780284 KB |
Output is correct |
9 |
Correct |
372 ms |
780400 KB |
Output is correct |
10 |
Correct |
391 ms |
780212 KB |
Output is correct |
11 |
Correct |
377 ms |
780328 KB |
Output is correct |
12 |
Correct |
381 ms |
780252 KB |
Output is correct |
13 |
Correct |
391 ms |
780304 KB |
Output is correct |
14 |
Correct |
395 ms |
780420 KB |
Output is correct |
15 |
Correct |
374 ms |
780448 KB |
Output is correct |
16 |
Correct |
370 ms |
780276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
396 ms |
780252 KB |
Output is correct |
2 |
Correct |
376 ms |
780348 KB |
Output is correct |
3 |
Correct |
378 ms |
780236 KB |
Output is correct |
4 |
Correct |
390 ms |
780196 KB |
Output is correct |
5 |
Correct |
390 ms |
780268 KB |
Output is correct |
6 |
Correct |
381 ms |
780240 KB |
Output is correct |
7 |
Correct |
384 ms |
780268 KB |
Output is correct |
8 |
Correct |
400 ms |
780284 KB |
Output is correct |
9 |
Correct |
378 ms |
780208 KB |
Output is correct |
10 |
Correct |
376 ms |
780168 KB |
Output is correct |
11 |
Incorrect |
395 ms |
780244 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |