Submission #8137211


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/












int N, L[55];
//---------------------------------------------------------------------------------------------------
int LL[55];
int getsm(int a, int b) { // L[a] + L[a + 1] + ... + L[b]
	int sm = LL[b];
	if (a) sm -= LL[a - 1];
	return sm;
}
//---------------------------------------------------------------------------------------------------
int memo[55];
int f(int idx, int mi, int ma) {
	if (0 <= memo[idx]) return memo[idx];
	if (idx == N) return 1;

	int lim = N;
	if (idx == 0) lim = N - 1;
	rep(i, idx, lim) {
		int sm = getsm(idx, i);
		if (mi <= sm and sm <= ma) {
			if (f(i + 1, mi, ma)) return memo[idx] = 1;
		}
	}

	return memo[idx] = 0;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> L[i];
	LL[0] = L[0];
	rep(i, 1, N) LL[i] = LL[i - 1] + L[i];

	vector<int> v;
	rep(i, 0, N) rep(j, i, N) {
		int sm = getsm(i, j);
		v.push_back(sm);
	}
	sort(all(v));
	v.erase(unique(all(v)), v.end());

	int n = v.size();
	int ans = inf;
	rep(i, 0, n) rep(j, i, n) {
		int mi = v[i];
		int ma = v[j];
		rep(k, 0, N + 1) memo[k] = -1;
		if (f(0, mi, ma)) chmin(ans, ma - mi);
	}
	cout << ans << endl;
}


Submission Info

Submission Time
Task D - 水ようかん (Mizuyokan)
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2533 Byte
Status AC
Exec Time 178 ms
Memory 256 KB

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3
Score / Max Score 0 / 0 10 / 10 27 / 27 63 / 63
Status
AC × 3
AC × 33
AC × 23
AC × 85
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt
Subtask1 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 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 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 AC 2 ms 256 KB
01-02.txt AC 2 ms 256 KB
01-03.txt AC 2 ms 256 KB
01-04.txt AC 2 ms 256 KB
01-05.txt AC 2 ms 256 KB
01-06.txt AC 2 ms 256 KB
01-07.txt AC 2 ms 256 KB
01-08.txt AC 2 ms 256 KB
01-09.txt AC 2 ms 256 KB
01-10.txt AC 2 ms 256 KB
01-11.txt AC 2 ms 256 KB
01-12.txt AC 2 ms 256 KB
01-13.txt AC 2 ms 256 KB
01-14.txt AC 2 ms 256 KB
01-15.txt AC 2 ms 256 KB
01-16.txt AC 1 ms 256 KB
01-17.txt AC 2 ms 256 KB
01-18.txt AC 2 ms 256 KB
01-19.txt AC 1 ms 256 KB
01-20.txt AC 1 ms 256 KB
01-21.txt AC 2 ms 256 KB
01-22.txt AC 2 ms 256 KB
01-23.txt AC 2 ms 256 KB
01-24.txt AC 2 ms 256 KB
01-25.txt AC 2 ms 256 KB
01-26.txt AC 2 ms 256 KB
01-27.txt AC 1 ms 256 KB
01-28.txt AC 2 ms 256 KB
01-29.txt AC 2 ms 256 KB
01-30.txt AC 2 ms 256 KB
02-01.txt AC 8 ms 256 KB
02-02.txt AC 4 ms 256 KB
02-03.txt AC 14 ms 256 KB
02-04.txt AC 7 ms 256 KB
02-05.txt AC 13 ms 256 KB
02-06.txt AC 6 ms 256 KB
02-07.txt AC 15 ms 256 KB
02-08.txt AC 14 ms 256 KB
02-09.txt AC 5 ms 256 KB
02-10.txt AC 2 ms 256 KB
02-11.txt AC 8 ms 256 KB
02-12.txt AC 4 ms 256 KB
02-13.txt AC 12 ms 256 KB
02-14.txt AC 7 ms 256 KB
02-15.txt AC 15 ms 256 KB
02-16.txt AC 6 ms 256 KB
02-17.txt AC 6 ms 256 KB
02-18.txt AC 14 ms 256 KB
02-19.txt AC 5 ms 256 KB
02-20.txt AC 2 ms 256 KB
03-01.txt AC 159 ms 256 KB
03-02.txt AC 158 ms 256 KB
03-03.txt AC 158 ms 256 KB
03-04.txt AC 136 ms 256 KB
03-05.txt AC 155 ms 256 KB
03-06.txt AC 156 ms 256 KB
03-07.txt AC 139 ms 256 KB
03-08.txt AC 54 ms 256 KB
03-09.txt AC 158 ms 256 KB
03-10.txt AC 131 ms 256 KB
03-11.txt AC 112 ms 256 KB
03-12.txt AC 128 ms 256 KB
03-13.txt AC 178 ms 256 KB
03-14.txt AC 159 ms 256 KB
03-15.txt AC 157 ms 256 KB
03-16.txt AC 126 ms 256 KB
03-17.txt AC 144 ms 256 KB
03-18.txt AC 155 ms 256 KB
03-19.txt AC 107 ms 256 KB
03-20.txt AC 145 ms 256 KB
03-21.txt AC 154 ms 256 KB
03-22.txt AC 173 ms 256 KB
03-23.txt AC 155 ms 256 KB
03-24.txt AC 150 ms 256 KB
03-25.txt AC 167 ms 256 KB
03-26.txt AC 160 ms 256 KB
03-27.txt AC 130 ms 256 KB
03-28.txt AC 52 ms 256 KB
03-29.txt AC 156 ms 256 KB
03-30.txt AC 162 ms 256 KB
03-31.txt AC 158 ms 256 KB
03-32.txt AC 165 ms 256 KB
sample-01.txt AC 2 ms 256 KB
sample-02.txt AC 1 ms 256 KB
sample-03.txt AC 1 ms 256 KB