結果

問題 No.1199 お菓子配り-2
ユーザー seiyu_kyoproseiyu_kyopro
提出日時 2021-11-11 01:17:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 433 ms / 1,000 ms
コード長 2,137 bytes
コンパイル時間 3,976 ms
コンパイル使用メモリ 183,616 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-05-01 14:51:55
合計ジャッジ時間 23,217 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 107 ms
5,504 KB
testcase_04 AC 266 ms
8,576 KB
testcase_05 AC 10 ms
5,376 KB
testcase_06 AC 16 ms
5,376 KB
testcase_07 AC 133 ms
6,016 KB
testcase_08 AC 179 ms
6,912 KB
testcase_09 AC 108 ms
5,760 KB
testcase_10 AC 27 ms
5,376 KB
testcase_11 AC 85 ms
5,376 KB
testcase_12 AC 82 ms
5,376 KB
testcase_13 AC 29 ms
5,376 KB
testcase_14 AC 24 ms
5,376 KB
testcase_15 AC 21 ms
5,376 KB
testcase_16 AC 174 ms
6,784 KB
testcase_17 AC 83 ms
5,376 KB
testcase_18 AC 180 ms
6,912 KB
testcase_19 AC 47 ms
5,376 KB
testcase_20 AC 322 ms
9,472 KB
testcase_21 AC 198 ms
7,168 KB
testcase_22 AC 105 ms
5,504 KB
testcase_23 AC 144 ms
6,272 KB
testcase_24 AC 201 ms
7,296 KB
testcase_25 AC 32 ms
5,376 KB
testcase_26 AC 227 ms
7,680 KB
testcase_27 AC 182 ms
7,040 KB
testcase_28 AC 430 ms
11,392 KB
testcase_29 AC 423 ms
11,392 KB
testcase_30 AC 426 ms
11,392 KB
testcase_31 AC 425 ms
11,392 KB
testcase_32 AC 424 ms
11,392 KB
testcase_33 AC 426 ms
11,392 KB
testcase_34 AC 430 ms
11,520 KB
testcase_35 AC 424 ms
11,392 KB
testcase_36 AC 426 ms
11,520 KB
testcase_37 AC 426 ms
11,520 KB
testcase_38 AC 422 ms
11,520 KB
testcase_39 AC 426 ms
11,392 KB
testcase_40 AC 423 ms
11,392 KB
testcase_41 AC 425 ms
11,392 KB
testcase_42 AC 427 ms
11,520 KB
testcase_43 AC 424 ms
11,520 KB
testcase_44 AC 433 ms
11,392 KB
testcase_45 AC 426 ms
11,392 KB
testcase_46 AC 426 ms
11,392 KB
testcase_47 AC 426 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iomanip>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <numeric>
#include <vector>
#include <climits>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }

template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;

int main() {
    int n, m;
    cin >> n >> m;

    vector a(n, vector<i64>(m));
    for(auto & i : a) for(auto & j : i) cin >> j;

    vector dp(n + 1, vector<i64>(2, -1e18));
    dp[0][0] = 0;

    rep(i, n) {
        i64 sum = accumulate(all(a[i]), 0ll);
        chmax(dp[i + 1][0], dp[i][1] - sum);
        chmax(dp[i + 1][0], dp[i][0]);
        chmax(dp[i + 1][1], dp[i][0] + sum);
        chmax(dp[i + 1][1], dp[i][1]);
    }

    cout << *max_element(all(dp[n])) << endl;

    return 0;
}
0