結果
問題 |
No.1199 お菓子配り-2
|
ユーザー |
![]() |
提出日時 | 2020-09-22 13:43:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 116 ms / 1,000 ms |
コード長 | 776 bytes |
コンパイル時間 | 1,678 ms |
コンパイル使用メモリ | 170,500 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-26 01:59:12 |
合計ジャッジ時間 | 8,713 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; #define rep2(i, a, n) for(int i = (a); i < (n); i++) #define rep(i, n) rep2(i,0,n) template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;} int main(){ cin.tie(nullptr);ios_base::sync_with_stdio(false); int n,m;cin>>n>>m; ll hoge; vector<ll> a(n,0); rep(i,n){ rep(j,m){ cin>>hoge; a[i]+=hoge; } } vector<vector<ll>> dp(n,vector<ll>(2,0)); dp[0][0]=a[0]; rep(i,n-1){ dp[i+1][0]=max(dp[i][0],dp[i][1]+a[i+1]); dp[i+1][1]=max(dp[i][1],dp[i][0]-a[i+1]); } /* rep(i,n){ cout<<a[i]<<" "; } cout<<endl; cout<<endl; rep(i,n){ cout<<dp[i][0]<<" "<<dp[i][1]<<endl; } */ cout<<max(dp[n-1][0],dp[n-1][0])<<endl; }