結果

問題 No.484 収穫
ユーザー sugim48sugim48
提出日時 2017-03-05 04:12:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,773 bytes
コンパイル時間 1,004 ms
コンパイル使用メモリ 108,192 KB
実行使用メモリ 34,604 KB
最終ジャッジ日時 2023-09-05 05:57:54
合計ジャッジ時間 31,264 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 9 ms
4,376 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2,266 ms
34,512 KB
testcase_18 AC 2,162 ms
34,376 KB
testcase_19 AC 2,248 ms
34,596 KB
testcase_20 AC 2,251 ms
34,472 KB
testcase_21 AC 2,241 ms
34,604 KB
testcase_22 WA -
testcase_23 AC 2,285 ms
34,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <fstream>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v; ll w; };

const int MOD = 1000000007;
const int _MOD = 1000000009;
double EPS = 1e-10;
const int INF = INT_MAX / 10;

int main() {
	int N; cin >> N;
	vector<int> a(N);
	rep(i, N) cin >> a[i];
	if (N == 1) {
		cout << a[0] << endl;
		return 0;
	}
	int lb = -1, ub = 1010000000;
	while (ub - lb > 1) {
		int mid = (lb + ub) / 2;
		vector<vector<int> > dpl(N + 1, vector<int>(N + 1, INF)), dpr = dpl;
		rep(i, N) dpl[i][i + 1] = dpr[i][i + 1] = 0;
		bool ok = false;
		for (int d = 1; d <= N; d++)
			for (int l = 0; l + d <= N; l++) {
				int r = l + d;
				if (mid - dpl[l][r] >= a[l]) {
					if (d == N) ok = true;
					if (l - 1 >= 0) dpl[l - 1][r] = min(dpl[l - 1][r], dpl[l][r] + 1);
					if (r + 1 <= N) dpr[l][r + 1] = min(dpr[l][r + 1], dpl[l][r] + r - l);
				}
				if (mid - dpr[l][r] >= a[r - 1]) {
					if (d == N) ok = true;
					if (l - 1 >= 0) dpl[l - 1][r] = min(dpl[l - 1][r], dpr[l][r] + r - l);
					if (r + 1 <= N) dpr[l][r + 1] = min(dpr[l][r + 1], dpr[l][r] + 1);
				}
			}
		if (ok) ub = mid;
		else lb = mid;
	}
	cout << ub << endl;
}
0