結果

問題 No.1199 お菓子配り-2
ユーザー kk
提出日時 2020-12-12 15:51:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 123 ms / 1,000 ms
コード長 702 bytes
コンパイル時間 3,224 ms
コンパイル使用メモリ 207,096 KB
実行使用メモリ 11,092 KB
最終ジャッジ日時 2023-10-20 02:08:36
合計ジャッジ時間 16,946 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 4 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 60 ms
5,020 KB
testcase_04 AC 76 ms
8,188 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 6 ms
4,348 KB
testcase_07 AC 39 ms
5,548 KB
testcase_08 AC 52 ms
6,604 KB
testcase_09 AC 33 ms
5,284 KB
testcase_10 AC 9 ms
4,348 KB
testcase_11 AC 25 ms
4,756 KB
testcase_12 AC 25 ms
4,756 KB
testcase_13 AC 10 ms
4,348 KB
testcase_14 AC 9 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 51 ms
6,340 KB
testcase_17 AC 26 ms
4,756 KB
testcase_18 AC 53 ms
6,604 KB
testcase_19 AC 15 ms
4,348 KB
testcase_20 AC 93 ms
9,244 KB
testcase_21 AC 57 ms
6,868 KB
testcase_22 AC 31 ms
5,020 KB
testcase_23 AC 43 ms
5,812 KB
testcase_24 AC 59 ms
6,868 KB
testcase_25 AC 11 ms
4,348 KB
testcase_26 AC 66 ms
7,396 KB
testcase_27 AC 54 ms
6,604 KB
testcase_28 AC 121 ms
11,092 KB
testcase_29 AC 123 ms
11,092 KB
testcase_30 AC 122 ms
11,092 KB
testcase_31 AC 121 ms
11,092 KB
testcase_32 AC 122 ms
11,092 KB
testcase_33 AC 121 ms
11,092 KB
testcase_34 AC 121 ms
11,092 KB
testcase_35 AC 121 ms
11,092 KB
testcase_36 AC 122 ms
11,092 KB
testcase_37 AC 121 ms
11,092 KB
testcase_38 AC 121 ms
11,092 KB
testcase_39 AC 121 ms
11,092 KB
testcase_40 AC 121 ms
11,092 KB
testcase_41 AC 121 ms
11,092 KB
testcase_42 AC 121 ms
11,092 KB
testcase_43 AC 122 ms
11,092 KB
testcase_44 AC 122 ms
11,092 KB
testcase_45 AC 122 ms
11,092 KB
testcase_46 AC 121 ms
11,092 KB
testcase_47 AC 121 ms
11,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const long long INF = 1LL<<60;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  cin >> n >> m;

  vector<vector<long long> > a(n, vector<long long>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> a[i][j];

  vector<long long> cur(2);
  cur[1] = -INF;

  for (int i = 0; i < n; i++) {
    vector<long long> nxt(2);

    long long sum = 0;
    for (int j = 0; j < m; j++)
      sum += a[i][j];
    nxt[0] = max(cur[0], cur[1] - sum);
    nxt[1] = max(cur[1], cur[0] + sum);
    cur = nxt;
  }

  cout << max(cur[0], cur[1]) << endl;
  
  return 0;
}
0