結果

問題 No.484 収穫
ユーザー 紙ぺーぱー紙ぺーぱー
提出日時 2017-02-10 23:46:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,271 ms / 3,000 ms
コード長 1,052 bytes
コンパイル時間 1,711 ms
コンパイル使用メモリ 164,944 KB
実行使用メモリ 34,592 KB
最終ジャッジ日時 2023-09-22 14:11:01
合計ジャッジ時間 17,472 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 20 ms
6,052 KB
testcase_10 AC 21 ms
6,032 KB
testcase_11 AC 21 ms
6,056 KB
testcase_12 AC 1,087 ms
34,356 KB
testcase_13 AC 801 ms
34,424 KB
testcase_14 AC 1,031 ms
34,324 KB
testcase_15 AC 1,026 ms
34,592 KB
testcase_16 AC 970 ms
34,356 KB
testcase_17 AC 1,705 ms
34,412 KB
testcase_18 AC 2,271 ms
34,364 KB
testcase_19 AC 1,317 ms
34,420 KB
testcase_20 AC 1,304 ms
34,384 KB
testcase_21 AC 1,308 ms
34,424 KB
testcase_22 AC 964 ms
34,556 KB
testcase_23 AC 970 ms
34,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int dp[2000][2000][2];
ll a[2000],t[2000];
int dfs(int l,int r,int k){
	if (dp[l][r][k] != -1) return dp[l][r][k];
    if (k == 0)
    {
        int x = dfs(l + 1, r, 0) + 1;
        int y = dfs(l + 1, r, 1) + r - l;
        dp[l][r][k]=min(x,y);
        if (t[l] < dp[l][r][k]) dp[l][r][k] = 1000000000;
    }
    else
    {
        int x = dfs(l, r-1, 1) + 1;
        int y = dfs(l, r-1, 0) + r - l;
        dp[l][r][k]=min(x,y);
        if (t[r] < dp[l][r][k]) dp[l][r][k] = 1000000000;
    }
    return dp[l][r][k];
        	
}
int f(ll x){
	for(int i=0;i<n;i++){
		t[i]=x-a[i];
		if(t[i]<0)return 0;
	}
	for(int i=0;i<n;i++)
		for(int j=i;j<n;j++){
			if(i!=j)dp[i][j][0]=dp[i][j][1]=-1;
			else dp[i][j][0]=dp[i][j][1]=0;
		}
		if(min(dfs(0,n-1,0),dfs(0,n-1,1))<1000000000)return 1;
		else return 0;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	ll l=0,r=10000000000;
	for(int iii=0;iii<40;iii++){
		ll m=(l+r)/2;
		if(f(m))r=m;
		else l=m;
	}
	cout<<r<<endl;
}
0