結果
問題 | No.1199 お菓子配り-2 |
ユーザー |
|
提出日時 | 2020-08-28 22:00:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 852 ms / 1,000 ms |
コード長 | 674 bytes |
コンパイル時間 | 2,464 ms |
コンパイル使用メモリ | 72,284 KB |
最終ジャッジ日時 | 2025-01-13 17:31:12 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include <iostream>#include <vector>using lint = long long;constexpr lint INF = 1LL << 60;void solve() {int n, m;std::cin >> n >> m;std::vector<lint> dp(2, -INF);dp[0] = 0;while (n--) {lint sum = 0;for (int i = 0; i < m; ++i) {lint x;std::cin >> x;sum += x;}auto ndp = dp;ndp[0] = std::max(ndp[0], dp[1] - sum);ndp[1] = std::max(ndp[1], dp[0] + sum);std::swap(dp, ndp);}std::cout << std::max(dp[0], dp[1]) << "\n";}int main() {std::cin.tie(nullptr);std::ios::sync_with_stdio(false);solve();return 0;}