Submission #465084

# Submission time Handle Problem Language Result Execution time Memory
465084 2021-08-15T07:32:27 Z jamezzz Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
15 / 100
336 ms 780376 KB
#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(pv!=-1&&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));
	if(pv==-1)return res;
	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:57:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |  sf("%d",&n);
      |    ^
joi2019_ho_t3.cpp:59:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   sf(" %c",&c);
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 323 ms 780376 KB Output is correct
2 Correct 318 ms 780244 KB Output is correct
3 Correct 323 ms 780256 KB Output is correct
4 Correct 327 ms 780204 KB Output is correct
5 Correct 328 ms 780276 KB Output is correct
6 Correct 325 ms 780284 KB Output is correct
7 Correct 320 ms 780240 KB Output is correct
8 Correct 327 ms 780248 KB Output is correct
9 Correct 319 ms 780204 KB Output is correct
10 Correct 317 ms 780292 KB Output is correct
11 Incorrect 318 ms 780240 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 323 ms 780376 KB Output is correct
2 Correct 318 ms 780244 KB Output is correct
3 Correct 323 ms 780256 KB Output is correct
4 Correct 327 ms 780204 KB Output is correct
5 Correct 328 ms 780276 KB Output is correct
6 Correct 325 ms 780284 KB Output is correct
7 Correct 320 ms 780240 KB Output is correct
8 Correct 327 ms 780248 KB Output is correct
9 Correct 319 ms 780204 KB Output is correct
10 Correct 317 ms 780292 KB Output is correct
11 Incorrect 318 ms 780240 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 331 ms 780168 KB Output is correct
2 Correct 319 ms 780228 KB Output is correct
3 Correct 321 ms 780312 KB Output is correct
4 Correct 321 ms 780356 KB Output is correct
5 Correct 332 ms 780296 KB Output is correct
6 Correct 319 ms 780228 KB Output is correct
7 Correct 330 ms 780228 KB Output is correct
8 Correct 336 ms 780208 KB Output is correct
9 Correct 317 ms 780228 KB Output is correct
10 Correct 326 ms 780304 KB Output is correct
11 Correct 322 ms 780228 KB Output is correct
12 Correct 328 ms 780216 KB Output is correct
13 Correct 325 ms 780224 KB Output is correct
14 Correct 327 ms 780356 KB Output is correct
15 Correct 324 ms 780264 KB Output is correct
16 Correct 320 ms 780268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 323 ms 780376 KB Output is correct
2 Correct 318 ms 780244 KB Output is correct
3 Correct 323 ms 780256 KB Output is correct
4 Correct 327 ms 780204 KB Output is correct
5 Correct 328 ms 780276 KB Output is correct
6 Correct 325 ms 780284 KB Output is correct
7 Correct 320 ms 780240 KB Output is correct
8 Correct 327 ms 780248 KB Output is correct
9 Correct 319 ms 780204 KB Output is correct
10 Correct 317 ms 780292 KB Output is correct
11 Incorrect 318 ms 780240 KB Output isn't correct
12 Halted 0 ms 0 KB -