結果
問題 | No.1199 お菓子配り-2 |
ユーザー |
|
提出日時 | 2020-08-28 21:38:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 422 ms / 1,000 ms |
コード長 | 700 bytes |
コンパイル時間 | 1,672 ms |
コンパイル使用メモリ | 167,580 KB |
実行使用メモリ | 11,604 KB |
最終ジャッジ日時 | 2024-11-14 03:03:26 |
合計ジャッジ時間 | 16,666 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define int long longtemplate<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;}