結果

問題 No.1199 お菓子配り-2
ユーザー Y17Y17
提出日時 2020-08-28 21:38:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 404 ms / 1,000 ms
コード長 700 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 164,756 KB
実行使用メモリ 11,608 KB
最終ジャッジ日時 2023-08-08 22:22:37
合計ジャッジ時間 16,259 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 100 ms
9,452 KB
testcase_04 AC 250 ms
10,744 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 15 ms
4,380 KB
testcase_07 AC 119 ms
7,460 KB
testcase_08 AC 162 ms
7,452 KB
testcase_09 AC 100 ms
7,460 KB
testcase_10 AC 26 ms
4,508 KB
testcase_11 AC 80 ms
7,508 KB
testcase_12 AC 78 ms
5,068 KB
testcase_13 AC 26 ms
4,380 KB
testcase_14 AC 23 ms
4,552 KB
testcase_15 AC 19 ms
4,380 KB
testcase_16 AC 159 ms
7,464 KB
testcase_17 AC 79 ms
7,388 KB
testcase_18 AC 172 ms
10,536 KB
testcase_19 AC 45 ms
7,260 KB
testcase_20 AC 301 ms
10,288 KB
testcase_21 AC 180 ms
11,084 KB
testcase_22 AC 96 ms
9,672 KB
testcase_23 AC 136 ms
10,156 KB
testcase_24 AC 187 ms
10,640 KB
testcase_25 AC 29 ms
4,680 KB
testcase_26 AC 212 ms
9,524 KB
testcase_27 AC 171 ms
7,596 KB
testcase_28 AC 392 ms
11,376 KB
testcase_29 AC 393 ms
11,432 KB
testcase_30 AC 399 ms
11,312 KB
testcase_31 AC 404 ms
11,316 KB
testcase_32 AC 400 ms
11,520 KB
testcase_33 AC 394 ms
11,308 KB
testcase_34 AC 400 ms
11,608 KB
testcase_35 AC 392 ms
11,320 KB
testcase_36 AC 396 ms
11,436 KB
testcase_37 AC 390 ms
11,312 KB
testcase_38 AC 396 ms
11,372 KB
testcase_39 AC 399 ms
11,320 KB
testcase_40 AC 394 ms
11,388 KB
testcase_41 AC 398 ms
11,332 KB
testcase_42 AC 393 ms
11,436 KB
testcase_43 AC 398 ms
11,312 KB
testcase_44 AC 401 ms
11,320 KB
testcase_45 AC 400 ms
11,608 KB
testcase_46 AC 397 ms
11,316 KB
testcase_47 AC 395 ms
11,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
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; }

int n, m;
int a[1010][1010];
int b[1010] = {};

int memo[1010][2];
int dp(int i, int x){
	if(i == n) return 0;
	if(memo[i][x] != -1) return memo[i][x];
	return memo[i][x] = max(dp(i+1, x), dp(i+1, x == 1 ? 0 : 1) + (x == 0 ? 1 : -1) * b[i] );
}

signed main(){
	cin >> n >> m;

	for(int i = 0;i < n;i++){
		for(int j = 0;j < m;j++){
			cin >> a[i][j];
			b[i] += a[i][j];
		}
	}

	memset(memo, -1, sizeof(memo));
	cout << dp(0, 0) << endl;

	return 0;
}
0