제출 #807478

#제출 시각아이디문제언어결과실행 시간메모리
807478happypotatoRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
280 ms524288 KiB
#include "railroad.h"

#include <bits/stdc++.h>
using namespace std;
#define int long long

vector<int> s, t;
int n;

int BruteDP() {
	int dp[(1 << n)][n];
	for (int conf = 0; conf < (1 << n); conf++) {
		for (int i = 0; i < n; i++) {
			dp[conf][i] = (conf == (1 << i) ? 0 : 1e18); 
		}
	}
	for (int bit = 2; bit <= n; bit++) {
		for (int conf = 0; conf < (1 << n); conf++) {
			if (__builtin_popcountll(conf) != bit) continue;
			for (int i = 0; i < n; i++) {
				if (conf & (1 << i)) {
					for (int j = 0; j < n; j++) {
						if (!bool(conf & (1 << j)) || i == j) continue;
						// cerr << "UPDATE " << conf << ' ' << i << ' ' << j << ' ' << dp[conf ^ (1 << i)][j] << ' ';
						// cerr << t[j] << ' ' << s[i] << endl;
						dp[conf][i] = min(dp[conf][i], dp[conf ^ (1 << i)][j] + max(0LL, t[j] - s[i]));
					}
				}
			}
		}
	}
	// for (int i = 0; i < (1 << n); i++) {
	// 	for (int j = 0; j < n; j++) cerr << dp[i][j] << ' ';
	// 	cerr << endl;
	// }
	int ans = 1e18;
	for (int i = 0; i < n; i++) ans = min(ans, dp[(1 << n) - 1][i]);
	return ans;
}

long long plan_roller_coaster(vector<int32_t> S, vector<int32_t> T) {
	n = S.size(); s.resize(n); t.resize(n);
	for (int i = 0; i < n; i++) {
		s[i] = S[i]; t[i] = T[i];
	}
	// for (int i = 0; i < n; i++) cerr << s[i] << ' '; cerr << endl;
	// for (int i = 0; i < n; i++) cerr << t[i] << ' '; cerr << endl;

	if (n <= 16) return BruteDP();
}

#undef int

컴파일 시 표준 에러 (stderr) 메시지

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:50:1: warning: control reaches end of non-void function [-Wreturn-type]
   50 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...