結果

問題 No.1199 お菓子配り-2
ユーザー magmag
提出日時 2020-09-22 13:43:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 1,000 ms
コード長 776 bytes
コンパイル時間 2,560 ms
コンパイル使用メモリ 168,972 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 08:50:43
合計ジャッジ時間 10,886 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 32 ms
4,380 KB
testcase_04 AC 78 ms
4,376 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 38 ms
4,380 KB
testcase_08 AC 52 ms
4,376 KB
testcase_09 AC 33 ms
4,380 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 25 ms
4,376 KB
testcase_12 AC 25 ms
4,380 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 51 ms
4,376 KB
testcase_17 AC 25 ms
4,376 KB
testcase_18 AC 53 ms
4,376 KB
testcase_19 AC 15 ms
4,380 KB
testcase_20 AC 95 ms
4,376 KB
testcase_21 AC 58 ms
4,380 KB
testcase_22 AC 31 ms
4,376 KB
testcase_23 AC 44 ms
4,376 KB
testcase_24 AC 60 ms
4,380 KB
testcase_25 AC 10 ms
4,380 KB
testcase_26 AC 67 ms
4,380 KB
testcase_27 AC 54 ms
4,376 KB
testcase_28 AC 124 ms
4,380 KB
testcase_29 AC 124 ms
4,380 KB
testcase_30 AC 126 ms
4,376 KB
testcase_31 AC 123 ms
4,376 KB
testcase_32 AC 124 ms
4,380 KB
testcase_33 AC 123 ms
4,376 KB
testcase_34 AC 125 ms
4,380 KB
testcase_35 AC 124 ms
4,380 KB
testcase_36 AC 124 ms
4,380 KB
testcase_37 AC 124 ms
4,376 KB
testcase_38 AC 124 ms
4,376 KB
testcase_39 AC 124 ms
4,376 KB
testcase_40 AC 124 ms
4,376 KB
testcase_41 AC 124 ms
4,376 KB
testcase_42 AC 126 ms
4,376 KB
testcase_43 AC 124 ms
4,380 KB
testcase_44 AC 123 ms
4,376 KB
testcase_45 AC 124 ms
4,376 KB
testcase_46 AC 124 ms
4,376 KB
testcase_47 AC 123 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0