Submission #3107871


Source Code Expand

Copy
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; std::vector<int> l(n), s(n + 1, 0);
	for(int i = 0; i < n; i++) cin >> l[i];
	for(int i = 0; i < n; i++) s[i + 1] = s[i] + l[i];
	
	std::vector<std::vector<std::vector<int>>> dp(2, std::vector<std::vector<int>>(n + 1, std::vector<int>(50001, -1)));
	dp[0][0][0] = 1e9;
	for(int i = 0; i < n; i++) {
		int cur = i % 2, inv = 1 - cur;
		
		for(int j = 0; j <= n; j++)
			for(int k = 0; k <= 50000; k++)
				dp[inv][j][k] = -1;
		
		for(int j = 0; j < n; j++) {
			for(int k = 0; k <= 50000; k++) {
				if(dp[cur][j][k] == -1) continue;
				
				{ // uncut
					int to = std::max(k, s[i + 1] - s[j]);
					dp[inv][j][to] = std::max(dp[inv][j][to], dp[cur][j][k]);
				}
				
				{ // cut
					int to = std::max(k, l[i]);
					int tmp = s[i] - s[j];
					dp[inv][i][to] = std::max(dp[inv][i][to], std::min(dp[cur][j][k], tmp));
				}
			}
		}
	}
	
	int mi = (1 << 30);
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= 50000; j++) {
			if(dp[n % 2][i][j] == -1) continue;
			int tmp = s[n] - s[i];
			mi = std::min(mi, j - std::min(dp[n % 2][i][j], tmp));
		}
	}
	
	cout << mi << endl;
	return 0;
}

Submission Info

Submission Time
Task D - 水ようかん (Mizuyokan)
User ecasdqina
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1277 Byte
Status
Exec Time 154 ms
Memory 30464 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt, sample-02.txt, sample-03.txt
Subtask1 10 / 10 sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt
Subtask2 27 / 27 sample-01.txt, sample-02.txt, sample-03.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-20.txt
Subtask3 63 / 63 sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-20.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt, 03-09.txt, 03-10.txt, 03-11.txt, 03-12.txt, 03-13.txt, 03-14.txt, 03-15.txt, 03-16.txt, 03-17.txt, 03-18.txt, 03-19.txt, 03-20.txt, 03-21.txt, 03-22.txt, 03-23.txt, 03-24.txt, 03-25.txt, 03-26.txt, 03-27.txt, 03-28.txt, 03-29.txt, 03-30.txt, 03-31.txt, 03-32.txt
Case Name Status Exec Time Memory
01-01.txt 18 ms 9856 KB
01-02.txt 16 ms 9216 KB
01-03.txt 18 ms 9856 KB
01-04.txt 18 ms 9856 KB
01-05.txt 18 ms 9856 KB
01-06.txt 18 ms 9856 KB
01-07.txt 18 ms 9856 KB
01-08.txt 18 ms 9856 KB
01-09.txt 18 ms 9856 KB
01-10.txt 18 ms 9856 KB
01-11.txt 18 ms 9856 KB
01-12.txt 18 ms 9856 KB
01-13.txt 18 ms 9856 KB
01-14.txt 18 ms 9856 KB
01-15.txt 18 ms 9856 KB
01-16.txt 18 ms 9856 KB
01-17.txt 18 ms 9856 KB
01-18.txt 18 ms 9856 KB
01-19.txt 3 ms 2816 KB
01-20.txt 18 ms 9856 KB
01-21.txt 18 ms 9856 KB
01-22.txt 18 ms 9856 KB
01-23.txt 18 ms 9856 KB
01-24.txt 18 ms 9856 KB
01-25.txt 18 ms 9856 KB
01-26.txt 18 ms 9856 KB
01-27.txt 18 ms 9856 KB
01-28.txt 18 ms 9856 KB
01-29.txt 18 ms 9856 KB
01-30.txt 18 ms 9856 KB
02-01.txt 150 ms 30464 KB
02-02.txt 150 ms 30464 KB
02-03.txt 150 ms 30464 KB
02-04.txt 150 ms 30464 KB
02-05.txt 150 ms 30464 KB
02-06.txt 151 ms 30464 KB
02-07.txt 150 ms 30464 KB
02-08.txt 150 ms 30464 KB
02-09.txt 150 ms 30464 KB
02-10.txt 150 ms 30464 KB
02-11.txt 150 ms 30464 KB
02-12.txt 150 ms 30464 KB
02-13.txt 150 ms 30464 KB
02-14.txt 150 ms 30464 KB
02-15.txt 150 ms 30464 KB
02-16.txt 150 ms 30464 KB
02-17.txt 150 ms 30464 KB
02-18.txt 150 ms 30464 KB
02-19.txt 150 ms 30464 KB
02-20.txt 150 ms 30464 KB
03-01.txt 153 ms 30464 KB
03-02.txt 153 ms 30464 KB
03-03.txt 153 ms 30464 KB
03-04.txt 152 ms 30464 KB
03-05.txt 153 ms 30464 KB
03-06.txt 153 ms 30464 KB
03-07.txt 154 ms 30464 KB
03-08.txt 152 ms 30464 KB
03-09.txt 153 ms 30464 KB
03-10.txt 152 ms 30464 KB
03-11.txt 151 ms 30464 KB
03-12.txt 151 ms 30464 KB
03-13.txt 151 ms 30464 KB
03-14.txt 151 ms 30464 KB
03-15.txt 153 ms 30464 KB
03-16.txt 152 ms 30464 KB
03-17.txt 153 ms 30464 KB
03-18.txt 153 ms 30464 KB
03-19.txt 151 ms 30464 KB
03-20.txt 152 ms 30464 KB
03-21.txt 153 ms 30464 KB
03-22.txt 153 ms 30464 KB
03-23.txt 154 ms 30464 KB
03-24.txt 153 ms 30464 KB
03-25.txt 153 ms 30464 KB
03-26.txt 152 ms 30464 KB
03-27.txt 152 ms 30464 KB
03-28.txt 150 ms 30464 KB
03-29.txt 152 ms 30464 KB
03-30.txt 152 ms 30464 KB
03-31.txt 153 ms 30464 KB
03-32.txt 153 ms 30464 KB
sample-01.txt 11 ms 7552 KB
sample-02.txt 2 ms 2176 KB
sample-03.txt 5 ms 3968 KB