結果

問題 No.1199 お菓子配り-2
コンテスト
ユーザー siman
提出日時 2021-08-22 07:04:26
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 364 ms / 1,000 ms
コード長 730 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,632 ms
コンパイル使用メモリ 148,864 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-05-06 04:52:28
合計ジャッジ時間 29,751 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:29:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   29 |   ll dp[N + 1][2];
      |         ^~~~~
main.cpp:29:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int N, M;
      |       ^
1 warning generated.

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;

  vector<ll> sum(N, 0);
  ll a;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      cin >> a;
      sum[i] += a;
    }
  }

  ll dp[N + 1][2];
  memset(dp, 0, sizeof(dp));

  for (int i = 0; i < N; ++i) {
    ll s = sum[i];
    dp[i + 1][0] = max(dp[i + 1][0], max(dp[i][0], dp[i][1] - s));
    dp[i + 1][1] = max(dp[i + 1][1], max(dp[i][1], dp[i][0] + s));
  }

  cout << max(dp[N][0], dp[N][1]) << endl;

  return 0;
}
0