結果
問題 | No.1199 お菓子配り-2 |
ユーザー |
![]() |
提出日時 | 2020-08-28 21:40:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 423 ms / 1,000 ms |
コード長 | 633 bytes |
コンパイル時間 | 1,835 ms |
コンパイル使用メモリ | 171,760 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-14 03:05:31 |
合計ジャッジ時間 | 17,141 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long int ll;typedef pair<ll, ll> P;typedef vector<ll> VI;typedef vector<VI> VVI;const ll MOD = 1000000007;const ll INF = 1e18;#define REP(i, n) for(int i = 0; i < n; i++)#define ALL(v) v.begin(), v.end()int main(){int n, m; cin >> n >> m;VI a(n,0); ll b;REP(i,n)REP(j,m){cin >> b;a[i]+=b;}VVI dp(n+1,VI(2,-INF));dp[0][0]=0;REP(i,n){dp[i+1][1]=dp[i][1];dp[i+1][0]=max(0ll,dp[i][0]);dp[i+1][1]=max(dp[i+1][1],dp[i][0]+a[i]);dp[i+1][0]=max(dp[i+1][0],dp[i][1]-a[i]);}ll ans=max(dp[n][0],dp[n][1]);cout << ans << endl;return 0;}