結果

問題 No.1199 お菓子配り-2
ユーザー kuhakukuhaku
提出日時 2020-08-28 21:36:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 397 ms / 1,000 ms
コード長 2,277 bytes
コンパイル時間 2,135 ms
コンパイル使用メモリ 205,112 KB
実行使用メモリ 11,256 KB
最終ジャッジ日時 2023-08-08 22:18:55
合計ジャッジ時間 16,102 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 95 ms
5,364 KB
testcase_04 AC 245 ms
9,776 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 14 ms
4,380 KB
testcase_07 AC 118 ms
4,872 KB
testcase_08 AC 160 ms
5,076 KB
testcase_09 AC 99 ms
4,568 KB
testcase_10 AC 23 ms
4,376 KB
testcase_11 AC 71 ms
4,380 KB
testcase_12 AC 72 ms
4,376 KB
testcase_13 AC 24 ms
4,380 KB
testcase_14 AC 22 ms
4,380 KB
testcase_15 AC 19 ms
4,384 KB
testcase_16 AC 150 ms
4,812 KB
testcase_17 AC 72 ms
5,148 KB
testcase_18 AC 164 ms
9,592 KB
testcase_19 AC 41 ms
4,972 KB
testcase_20 AC 287 ms
9,180 KB
testcase_21 AC 180 ms
10,696 KB
testcase_22 AC 96 ms
8,896 KB
testcase_23 AC 129 ms
9,376 KB
testcase_24 AC 183 ms
9,688 KB
testcase_25 AC 27 ms
4,380 KB
testcase_26 AC 200 ms
5,680 KB
testcase_27 AC 164 ms
4,968 KB
testcase_28 AC 376 ms
10,964 KB
testcase_29 AC 360 ms
11,096 KB
testcase_30 AC 361 ms
11,012 KB
testcase_31 AC 365 ms
10,916 KB
testcase_32 AC 375 ms
10,980 KB
testcase_33 AC 359 ms
10,916 KB
testcase_34 AC 366 ms
11,008 KB
testcase_35 AC 367 ms
11,240 KB
testcase_36 AC 389 ms
11,048 KB
testcase_37 AC 368 ms
10,916 KB
testcase_38 AC 360 ms
11,032 KB
testcase_39 AC 367 ms
11,032 KB
testcase_40 AC 359 ms
10,960 KB
testcase_41 AC 359 ms
10,912 KB
testcase_42 AC 375 ms
10,972 KB
testcase_43 AC 369 ms
10,916 KB
testcase_44 AC 363 ms
11,256 KB
testcase_45 AC 369 ms
11,096 KB
testcase_46 AC 362 ms
11,116 KB
testcase_47 AC 397 ms
11,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
void co() { cout << endl; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << endl; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18L+1;
constexpr ll MOD = 1e9L+7;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void){
    ll n, m;
    cin >> n >> m;
    Vec a(n);
    rep(i, n){
        rep(j, m){
            ll b;
            cin >> b;
            a[i] += b;
        }
    }

    Vec2<ll> dp(n + 1, Vec(n + 1, -LINF));
    dp[0][0] = 0;
    rep(i, n){
        rep(j, n + 1) chmax(dp[i + 1][j], dp[i][j]);
        rep(j, n){
            if(j & 1) chmax(dp[i + 1][j + 1], dp[i][j] - a[i]);
            else
                chmax(dp[i + 1][j + 1], dp[i][j] + a[i]);
        }
    }
    ll ans = *max_element(all(dp[n]));
    co(ans);

    return 0;
}
0