結果

問題 No.1199 お菓子配り-2
ユーザー rabimearabimea
提出日時 2023-01-27 03:48:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 1,000 ms
コード長 947 bytes
コンパイル時間 3,616 ms
コンパイル使用メモリ 199,296 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-10 00:45:45
合計ジャッジ時間 16,093 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 34 ms
4,380 KB
testcase_04 AC 84 ms
4,384 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 6 ms
4,384 KB
testcase_07 AC 42 ms
4,380 KB
testcase_08 AC 57 ms
4,380 KB
testcase_09 AC 34 ms
4,388 KB
testcase_10 AC 9 ms
4,384 KB
testcase_11 AC 27 ms
4,388 KB
testcase_12 AC 27 ms
4,388 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 7 ms
4,384 KB
testcase_16 AC 55 ms
4,384 KB
testcase_17 AC 27 ms
4,380 KB
testcase_18 AC 58 ms
4,380 KB
testcase_19 AC 16 ms
4,380 KB
testcase_20 AC 102 ms
4,380 KB
testcase_21 AC 62 ms
4,384 KB
testcase_22 AC 34 ms
4,380 KB
testcase_23 AC 47 ms
4,384 KB
testcase_24 AC 64 ms
4,380 KB
testcase_25 AC 10 ms
4,380 KB
testcase_26 AC 72 ms
4,380 KB
testcase_27 AC 58 ms
4,384 KB
testcase_28 AC 133 ms
4,380 KB
testcase_29 AC 134 ms
4,384 KB
testcase_30 AC 133 ms
4,380 KB
testcase_31 AC 134 ms
4,384 KB
testcase_32 AC 134 ms
4,384 KB
testcase_33 AC 134 ms
4,380 KB
testcase_34 AC 133 ms
4,380 KB
testcase_35 AC 133 ms
4,380 KB
testcase_36 AC 133 ms
4,384 KB
testcase_37 AC 134 ms
4,384 KB
testcase_38 AC 133 ms
4,384 KB
testcase_39 AC 133 ms
4,380 KB
testcase_40 AC 133 ms
4,384 KB
testcase_41 AC 133 ms
4,380 KB
testcase_42 AC 133 ms
4,384 KB
testcase_43 AC 133 ms
4,380 KB
testcase_44 AC 132 ms
4,380 KB
testcase_45 AC 134 ms
4,384 KB
testcase_46 AC 134 ms
4,384 KB
testcase_47 AC 133 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using pii = pair <int, int>;
//~ const ll mod = 998244353;
const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const int N = 1e3 + 11;

ll a[N];
ll f[N][2];

void upd(ll &a, ll b) {
	if(a < b) a = b;
}

const ll inf = 1e18;

int main() {
	ios :: sync_with_stdio(false);
	
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++) {
			ll x; cin >> x;
			a[i] += x;
		}
	
	for(int i = 0; i < N; i ++)
		for(int j : {0, 1})
			f[i][j] = -inf;
	
	f[0][0] = 0;
	for(int i = 1; i <= n; i ++) {
		upd(f[i][0], f[i - 1][0]);
		upd(f[i][1], f[i - 1][1]);
		
		upd(f[i][1], f[i - 1][0] + a[i]);
		upd(f[i][0], f[i - 1][1] - a[i]);
	}
	
	cout << max(f[n][0], f[n][1]) << '\n';
}
0