結果

問題 No.484 収穫
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2017-02-13 11:10:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,878 bytes
コンパイル時間 1,114 ms
コンパイル使用メモリ 145,176 KB
実行使用メモリ 42,548 KB
最終ジャッジ日時 2023-08-28 15:32:19
合計ジャッジ時間 3,099 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,376 KB
testcase_01 AC 6 ms
4,380 KB
testcase_02 AC 7 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:48: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
  rep(i, 2)rep(j, 2010)rep(k, 2010) dp[i][j][k] = INF;
                                    ~~~~~~~~~~~~^~~~~
main.cpp:7:31: note: within this loop
 #define rep(i,n) for(int i=0;i<(n);i++)
                               ^
main.cpp:31:23: note: in expansion of macro ‘rep’
  rep(i, 2)rep(j, 2010)rep(k, 2010) dp[i][j][k] = INF;
                       ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

//dp[l][r][isright] := (l,r)が未収穫で、現在のセル(isrigt=0のときl, r)にいるための最短時刻
ll dp[2010][2010][2];
int n;
ll a[2010];

int main(void){
	cin >> n; rep(i, n) cin >> a[i];
	if(n == 1){
		printf("%lld\n", a[0]); return 0;
	}
	rep(i, 2)rep(j, 2010)rep(k, 2010) dp[i][j][k] = INF;
	dp[0][n - 1][0] = a[0];
	dp[0][n - 1][1] = a[n - 1];
	for (int len = n; len >= 0; --len){
		for (int i = 0; i + len <= n; ++i){
			rep(k, 2){
				//左端が i , 右端が j				
				int j = i + len;
				if(dp[i][j][k] == INF || i >= j) continue;
				ll time = dp[i][j][k];
				if(k == 0){//現在のセルが i の時
					//i->i+1
					if(time + 1 >= a[i + 1]) chmin(dp[i + 1][j][0], time + 1);
					else chmin(dp[i + 1][j][0], a[i + 1]);
					//i->j-1
					if(time + len >= a[j - 1]) chmin(dp[i][j - 1][1], time + len);
					else chmin(dp[i][j - 1][1], a[j - 1]);
				}else{//現在のセルが j の時
					//j->j-1
					if(time + 1 >= a[j - 1]) chmin(dp[i][j - 1][1], time + 1);
					else chmin(dp[i][j - 1][1], a[j - 1]);
					//j->i+1
					if(time + 1 >= a[i + 1]) chmin(dp[i + 1][j][0], time + len);
					else chmin(dp[i + 1][j][0], a[i + 1]);
				}
			}
		}
	}
	ll ans = INF;
	rep(i, n)rep(j, 2) chmin(ans, dp[i][i][j]);
	printf("%lld\n", ans);
	return 0;
}
0