結果

問題 No.1199 お菓子配り-2
ユーザー tnakao0123tnakao0123
提出日時 2020-08-30 19:27:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 1,000 ms
コード長 1,034 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 90,572 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-09 18:20:31
合計ジャッジ時間 10,429 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 33 ms
4,376 KB
testcase_04 AC 79 ms
4,508 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 40 ms
4,380 KB
testcase_08 AC 55 ms
4,376 KB
testcase_09 AC 33 ms
4,380 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 26 ms
4,376 KB
testcase_12 AC 25 ms
4,508 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 7 ms
4,384 KB
testcase_16 AC 53 ms
4,380 KB
testcase_17 AC 26 ms
4,380 KB
testcase_18 AC 54 ms
4,376 KB
testcase_19 AC 15 ms
4,376 KB
testcase_20 AC 97 ms
4,380 KB
testcase_21 AC 59 ms
4,380 KB
testcase_22 AC 32 ms
4,380 KB
testcase_23 AC 46 ms
4,380 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 55 ms
4,376 KB
testcase_28 AC 122 ms
4,380 KB
testcase_29 AC 126 ms
4,384 KB
testcase_30 AC 126 ms
4,376 KB
testcase_31 AC 127 ms
4,376 KB
testcase_32 AC 129 ms
4,376 KB
testcase_33 AC 127 ms
4,376 KB
testcase_34 AC 125 ms
4,380 KB
testcase_35 AC 127 ms
4,376 KB
testcase_36 AC 131 ms
4,380 KB
testcase_37 AC 127 ms
4,380 KB
testcase_38 AC 126 ms
4,380 KB
testcase_39 AC 129 ms
4,376 KB
testcase_40 AC 126 ms
4,380 KB
testcase_41 AC 125 ms
4,380 KB
testcase_42 AC 121 ms
4,380 KB
testcase_43 AC 125 ms
4,380 KB
testcase_44 AC 127 ms
4,376 KB
testcase_45 AC 131 ms
4,380 KB
testcase_46 AC 128 ms
4,380 KB
testcase_47 AC 128 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1199.cc:  No.1199 お菓子配り-2 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_M = 1000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;

/* global variables */

ll dp[MAX_N + 1][2];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  dp[0][0] = -LINF;
  dp[0][1] = 0;

  for (int i = 0; i < n; i++) {
    ll asum = 0;
    for (int j = 0; j < m; j++) {
      ll aij;
      scanf("%lld", &aij);
      asum += aij;
    }

    dp[i + 1][0] = max(dp[i][0], dp[i][1] + asum);
    dp[i + 1][1] = max(dp[i][1], dp[i][0] - asum);
  }

  printf("%lld\n", max(dp[n][0], dp[n][1]));
  return 0;
}
0