답안 #636806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
636806 2022-08-30T08:55:37 Z dsabolic 메기 농장 (IOI22_fish) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 305;

ll dp[N][N][2][2];
int n, m;
vector<int>& x;
vector<int>& y;
vector<int>& w;

int ima(int i, int j) {
	auto it = lower_bound(x.begin(), x.end(), i);
	if(it == x.end()) return 0;
	if(*it == i && y[it - x.begin()] == j) return w[it - x.begin()];
	else return 0;
}

ll solve(int i, int hp, bool f1, bool f2) {
	if(i == n) return 0;
	ll& ret = dp[i][hp][f1][f2];
	if(ret != -1) return ret;
	ret = 0;
	
	if(f2) {
		for(int h = 0; h <= n; ++h) {
			if(h == 0) {
				ret = max(ret, solve(i + 1, 0, 0, 1));
			} else {
				//ret = max(ret, solve(i + 1, 0, 0, 0) + ima(i - 1, h) + ima(i + 1, h));
				if(hp == h) ret = max(ret, solve(i + 1, h, 0, 0) + ima(i + 1, h));
				else ret = max(ret, solve(i + 1, h, 0, 0) + ima(i + 1, h) + ima(i - 1, h));
			}
		}
	} else {
		if(!f1) {
			for(int h = hp + 1; h <= n; ++h) {
				ret = max(ret, solve(i + 1, h, 0, 0) + ima(i - 1, h) + ima(i + 1, h));
			}
		}
		for(int h = hp; h >= 0; --h) {
			if(h == 0) {
				ret = max(ret, solve(i + 1, hp, 0, 1));
			} else {
				ret = max(ret, solve(i + 1, h, 1, 0) + ima(i + 1, h) - (h == hp) * ima(i, h));
			}
		}
	}
	
	return ret;
}

ll max_weights(int z, int d, vector<int>& a, vector<int>& b, vector<int>& c) {
	memset(dp, -1, sizeof dp);
	x = a, y = b, w = c;
	n = z, m = d;
	return solve(0, 0, 0, 0);
}

Compilation message

fish.cpp:10:14: error: 'x' declared as reference but not initialized
   10 | vector<int>& x;
      |              ^
fish.cpp:11:14: error: 'y' declared as reference but not initialized
   11 | vector<int>& y;
      |              ^
fish.cpp:12:14: error: 'w' declared as reference but not initialized
   12 | vector<int>& w;
      |              ^