답안 #465083

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465083 2021-08-15T07:31:56 Z jamezzz Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
340 ms 780268 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(p!=-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);
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 338 ms 780228 KB Output is correct
2 Correct 337 ms 780260 KB Output is correct
3 Correct 321 ms 780228 KB Output is correct
4 Incorrect 340 ms 780256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 338 ms 780228 KB Output is correct
2 Correct 337 ms 780260 KB Output is correct
3 Correct 321 ms 780228 KB Output is correct
4 Incorrect 340 ms 780256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 325 ms 780268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 338 ms 780228 KB Output is correct
2 Correct 337 ms 780260 KB Output is correct
3 Correct 321 ms 780228 KB Output is correct
4 Incorrect 340 ms 780256 KB Output isn't correct
5 Halted 0 ms 0 KB -