結果

問題 No.1199 お菓子配り-2
ユーザー Y17Y17
提出日時 2020-08-28 21:38:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 438 ms / 1,000 ms
コード長 700 bytes
コンパイル時間 1,778 ms
コンパイル使用メモリ 162,564 KB
実行使用メモリ 11,728 KB
最終ジャッジ日時 2024-04-26 14:31:24
合計ジャッジ時間 16,550 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 107 ms
8,432 KB
testcase_04 AC 270 ms
10,904 KB
testcase_05 AC 10 ms
6,940 KB
testcase_06 AC 16 ms
6,940 KB
testcase_07 AC 129 ms
8,048 KB
testcase_08 AC 181 ms
7,628 KB
testcase_09 AC 110 ms
6,944 KB
testcase_10 AC 28 ms
6,940 KB
testcase_11 AC 84 ms
6,944 KB
testcase_12 AC 82 ms
6,940 KB
testcase_13 AC 29 ms
6,944 KB
testcase_14 AC 24 ms
6,944 KB
testcase_15 AC 20 ms
6,944 KB
testcase_16 AC 171 ms
7,796 KB
testcase_17 AC 79 ms
8,260 KB
testcase_18 AC 173 ms
10,664 KB
testcase_19 AC 48 ms
8,220 KB
testcase_20 AC 306 ms
10,660 KB
testcase_21 AC 195 ms
11,324 KB
testcase_22 AC 104 ms
10,844 KB
testcase_23 AC 146 ms
10,592 KB
testcase_24 AC 201 ms
10,972 KB
testcase_25 AC 31 ms
6,944 KB
testcase_26 AC 220 ms
8,380 KB
testcase_27 AC 177 ms
7,644 KB
testcase_28 AC 431 ms
11,556 KB
testcase_29 AC 420 ms
11,608 KB
testcase_30 AC 424 ms
11,584 KB
testcase_31 AC 431 ms
11,652 KB
testcase_32 AC 438 ms
11,436 KB
testcase_33 AC 432 ms
11,532 KB
testcase_34 AC 432 ms
11,476 KB
testcase_35 AC 426 ms
11,400 KB
testcase_36 AC 421 ms
11,492 KB
testcase_37 AC 424 ms
11,580 KB
testcase_38 AC 429 ms
11,528 KB
testcase_39 AC 431 ms
11,416 KB
testcase_40 AC 425 ms
11,584 KB
testcase_41 AC 425 ms
11,424 KB
testcase_42 AC 428 ms
11,728 KB
testcase_43 AC 433 ms
11,620 KB
testcase_44 AC 428 ms
11,412 KB
testcase_45 AC 427 ms
11,660 KB
testcase_46 AC 416 ms
11,416 KB
testcase_47 AC 427 ms
11,452 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