답안 #486637

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486637 2021-11-12T07:49:55 Z my04 Candies (JOI18_candies) C++17
0 / 100
29 ms 63172 KB
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

void setIO(string name = "") {
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	if (sz(name)) {
		freopen((name + ".in").c_str(), "r", stdin);
		freopen((name + ".out").c_str(), "w", stdout);
	}
}

const int inf = 1e9;
const ll INF = 1e18;            
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

int n;
ll a[2005];
ll dp[2005][2005][2];


void solve() {
	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i <= n + 1; i++) {
		for (int j = 1; j <= n + 1; j++) {
			for (int k = 0; k < 2; k++) {
				dp[i][j][k] = -inf;
			}
		}
	}

	dp[1][1][1] = a[1];
	dp[1][0][0] = 0;

	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < i; j++) {
			dp[i][j + 1][1] = max(dp[i][j + 1][1], dp[i - 1][j][0] + a[i]);						
			dp[i][j][0] = max(dp[i][j][0], max(dp[i - 1][j][0], dp[i - 1][j][1]));
		}
	}	

	for (int i = 1; i <= (n + 1) / 2; i++) {
		cout << max(dp[n][i][1], dp[n][i][0]) << '\n';
	}
}                   	

main() {
	setIO();
	
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
	}
	
	return 0;
}

Compilation message

candies.cpp:64:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   64 | main() {
      | ^~~~
candies.cpp: In function 'void setIO(std::string)':
candies.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen((name + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   freopen((name + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 63172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 63172 KB Output isn't correct
2 Halted 0 ms 0 KB -