結果
問題 | No.1199 お菓子配り-2 |
ユーザー |
![]() |
提出日時 | 2020-08-28 21:58:43 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 959 ms / 1,000 ms |
コード長 | 1,612 bytes |
コンパイル時間 | 2,385 ms |
コンパイル使用メモリ | 194,772 KB |
最終ジャッジ日時 | 2025-01-13 17:25:57 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include<bits/stdc++.h>using namespace std;typedef long long ll;constexpr int Inf = 2000000010;constexpr ll INF= 2000000000000000000;constexpr ll MOD = 1000000007;const double PI = 3.1415926535897;typedef pair<int,int> P;typedef pair<int,P> PP;template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return 1;}return 0;}template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return 1;}return 0;}ll mod(ll val, ll M) {ll res = val % M;if(res < 0) {res += M;}return res;}template<typename T>T RS(T N, T P, T M){if(P == 0) {return 1;}if(P < 0) {return 0;}if(P % 2 == 0){ll t = RS(N, P/2, M);if(M == -1) return t * t;return t * t % M;}if(M == -1) {return N * RS(N,P - 1,M);}return N * RS(N, P-1, M) % M;}ll dp[1010][2] = {-INF}; //dp[i][j] = i番目のお菓子まででの幸せ度の最大値、ただしj = 0の時は正、j = 1の時は負int main() {int N,M;cin >> N >> M;vector<ll> vec(N);for(int i = 0;i < N;i++) {ll cnt = 0;for(int j = 0;j < M;j++) {ll A;cin >> A;cnt += A;}vec.at(i) = cnt;}dp[0][0] = 0;for(int i = 0;i < N;i++) {chmax(dp[i + 1][0],dp[i][1] - vec.at(i));chmax(dp[i + 1][0],dp[i][0]);chmax(dp[i + 1][1],dp[i][0] + vec.at(i));chmax(dp[i + 1][1],dp[i][1]);}cout << max(dp[N][0],dp[N][1]) << endl;}