結果

問題 No.1199 お菓子配り-2
ユーザー Example0911Example0911
提出日時 2020-08-28 21:34:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 1,000 ms
コード長 850 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 167,944 KB
実行使用メモリ 19,460 KB
最終ジャッジ日時 2023-08-08 22:16:20
合計ジャッジ時間 9,251 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,668 KB
testcase_01 AC 4 ms
11,556 KB
testcase_02 AC 5 ms
11,828 KB
testcase_03 AC 38 ms
17,768 KB
testcase_04 AC 85 ms
18,816 KB
testcase_05 AC 7 ms
11,620 KB
testcase_06 AC 9 ms
13,896 KB
testcase_07 AC 44 ms
15,716 KB
testcase_08 AC 58 ms
15,656 KB
testcase_09 AC 37 ms
15,868 KB
testcase_10 AC 13 ms
13,668 KB
testcase_11 AC 29 ms
15,668 KB
testcase_12 AC 29 ms
13,620 KB
testcase_13 AC 13 ms
13,600 KB
testcase_14 AC 12 ms
13,744 KB
testcase_15 AC 10 ms
13,820 KB
testcase_16 AC 56 ms
15,776 KB
testcase_17 AC 30 ms
15,728 KB
testcase_18 AC 60 ms
18,556 KB
testcase_19 AC 19 ms
15,724 KB
testcase_20 AC 101 ms
18,160 KB
testcase_21 AC 66 ms
19,024 KB
testcase_22 AC 38 ms
18,032 KB
testcase_23 AC 51 ms
18,376 KB
testcase_24 AC 67 ms
18,512 KB
testcase_25 AC 14 ms
13,716 KB
testcase_26 AC 73 ms
17,768 KB
testcase_27 AC 60 ms
15,656 KB
testcase_28 AC 132 ms
19,232 KB
testcase_29 AC 131 ms
19,232 KB
testcase_30 AC 131 ms
19,240 KB
testcase_31 AC 131 ms
19,232 KB
testcase_32 AC 132 ms
19,316 KB
testcase_33 AC 132 ms
19,176 KB
testcase_34 AC 132 ms
19,372 KB
testcase_35 AC 131 ms
19,168 KB
testcase_36 AC 131 ms
19,180 KB
testcase_37 AC 133 ms
19,320 KB
testcase_38 AC 132 ms
19,460 KB
testcase_39 AC 131 ms
19,296 KB
testcase_40 AC 133 ms
19,244 KB
testcase_41 AC 132 ms
19,168 KB
testcase_42 AC 131 ms
19,384 KB
testcase_43 AC 131 ms
19,304 KB
testcase_44 AC 130 ms
19,372 KB
testcase_45 AC 131 ms
19,228 KB
testcase_46 AC 132 ms
19,172 KB
testcase_47 AC 132 ms
19,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

//#define int long long

#define ll long long
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define P pair<ll,ll>
#define ld long double
ll INF = (1LL << 60);
int mod = 1000000007;

ll a[1001][1001];
ll dp[1010][1010];
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll N, M; cin >> N >> M;
	rep(i, N) {
		rep(j, M) {
			cin >> a[i][j];
		}
	}
	vector<ll>sum(N);
	rep(i, N) {
		ll now = 0;
		rep(j, M) {
			now += a[i][j];
		}
		sum[i] = now;
	}
	rep(i, 1010)rep(j, 1010)dp[i][j] = -INF;
	dp[0][0] = 0;
	rep(i, N) {
		rep(j, 1009) {
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			ll tmp = 1;
			if (j % 2 == 1)tmp = -1;
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + tmp * sum[i]);
		}
	}
	ll ans = 0;
	rep(i, 1010)ans = max(ans, dp[N][i]);
	cout << ans << endl;
	return 0;
}
0