結果

問題 No.1199 お菓子配り-2
ユーザー kuhakukuhaku
提出日時 2020-08-28 21:36:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 443 ms / 1,000 ms
コード長 2,277 bytes
コンパイル時間 2,497 ms
コンパイル使用メモリ 200,796 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-04-26 14:27:51
合計ジャッジ時間 17,438 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 111 ms
6,944 KB
testcase_04 AC 273 ms
9,856 KB
testcase_05 AC 10 ms
6,940 KB
testcase_06 AC 16 ms
6,944 KB
testcase_07 AC 127 ms
6,940 KB
testcase_08 AC 179 ms
6,940 KB
testcase_09 AC 109 ms
6,944 KB
testcase_10 AC 27 ms
6,940 KB
testcase_11 AC 83 ms
6,940 KB
testcase_12 AC 82 ms
6,940 KB
testcase_13 AC 29 ms
6,940 KB
testcase_14 AC 24 ms
6,944 KB
testcase_15 AC 20 ms
6,944 KB
testcase_16 AC 174 ms
6,944 KB
testcase_17 AC 81 ms
6,940 KB
testcase_18 AC 186 ms
9,728 KB
testcase_19 AC 49 ms
6,944 KB
testcase_20 AC 321 ms
9,344 KB
testcase_21 AC 208 ms
10,880 KB
testcase_22 AC 108 ms
9,088 KB
testcase_23 AC 151 ms
9,728 KB
testcase_24 AC 204 ms
9,728 KB
testcase_25 AC 31 ms
6,944 KB
testcase_26 AC 230 ms
6,944 KB
testcase_27 AC 182 ms
6,944 KB
testcase_28 AC 428 ms
11,136 KB
testcase_29 AC 429 ms
11,136 KB
testcase_30 AC 422 ms
11,136 KB
testcase_31 AC 431 ms
11,136 KB
testcase_32 AC 443 ms
11,392 KB
testcase_33 AC 435 ms
11,136 KB
testcase_34 AC 432 ms
11,136 KB
testcase_35 AC 425 ms
11,136 KB
testcase_36 AC 433 ms
11,264 KB
testcase_37 AC 437 ms
11,136 KB
testcase_38 AC 435 ms
11,264 KB
testcase_39 AC 434 ms
11,136 KB
testcase_40 AC 435 ms
11,264 KB
testcase_41 AC 432 ms
11,136 KB
testcase_42 AC 440 ms
11,392 KB
testcase_43 AC 432 ms
11,264 KB
testcase_44 AC 433 ms
11,264 KB
testcase_45 AC 438 ms
11,136 KB
testcase_46 AC 435 ms
11,136 KB
testcase_47 AC 432 ms
11,136 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