結果
問題 | No.1199 お菓子配り-2 |
ユーザー |
![]() |
提出日時 | 2020-08-28 21:55:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 420 ms / 1,000 ms |
コード長 | 886 bytes |
コンパイル時間 | 1,850 ms |
コンパイル使用メモリ | 169,616 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-14 03:27:39 |
合計ジャッジ時間 | 16,455 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h>using namespace std;/* typedef */typedef long long ll;typedef pair<int, int> pii;/* constant */const int INF = 1 << 30;const ll LINF = 1LL << 50;const int NIL = -1;const int MAX = 10000;const int mod = 1000000007;const double pi = 3.141592653589;/* global variables *//* function *//* main */int main(){int N, M;cin >> N >> M;vector<ll> happinessDegrees(N, 0LL);for (int i = 0; i < N; i++) {for (int j = 0; j < M; j++) {ll hp; cin >> hp;happinessDegrees[i] += hp;}}vector<ll> dp(N+1, -LINF); // N個選んだときのMaxdp[0] = 0;for (int i = 0; i < N; i++) {for (int j = 0; j <= i; j++) {dp[j + 1] = max(dp[j + 1], dp[j] + happinessDegrees[i] * (j % 2 ? -1 : 1));}}cout << *max_element(dp.begin(), dp.end()) << '\n';}