結果
問題 | No.1199 お菓子配り-2 |
ユーザー |
|
提出日時 | 2020-08-28 21:37:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 209 ms / 1,000 ms |
コード長 | 1,945 bytes |
コンパイル時間 | 4,311 ms |
コンパイル使用メモリ | 201,352 KB |
最終ジャッジ日時 | 2025-01-13 16:47:43 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h>#ifdef DEBUG#include <Mylib/Debug/debug.cpp>#else#define dump(...) ((void)0)#endiftemplate <typename T, typename U>bool chmin(T &a, const U &b){return (a > b ? a = b, true : false);}template <typename T, typename U>bool chmax(T &a, const U &b){return (a < b ? a = b, true : false);}template <typename T, size_t N, typename U>void fill_array(T (&a)[N], const U &v){std::fill((U*)a, (U*)(a + N), v);}template <typename T>auto make_vector(int n, int m, const T &value){return std::vector<std::vector<T>>(n, std::vector<T>(m, value));}template <typename T>std::ostream& operator<<(std::ostream &s, const std::vector<T> &a){for(auto it = a.begin(); it != a.end(); ++it){if(it != a.begin()) s << " ";s << *it;}return s;}template <typename T>std::istream& operator>>(std::istream &s, std::vector<T> &a){for(auto &x : a) s >> x;return s;}namespace solver{void init(){std::cin.tie(0);std::ios::sync_with_stdio(false);std::cout << std::fixed << std::setprecision(12);std::cerr << std::fixed << std::setprecision(12);std::cin.exceptions(std::ios_base::failbit);}void solve(){int N, M; std::cin >> N >> M;auto A = make_vector<int64_t>(N, M, 0);std::cin >> A;std::deque<int64_t> B(N);for(int i = 0; i < N; ++i) B[i] = std::accumulate(A[i].begin(), A[i].end(), 0LL);auto dp = make_vector<int64_t>(2, N + 1, -(1LL << 50));dp[0][0] = 0;for(int i = 0; i < N; ++i){chmax(dp[0][i + 1], dp[0][i]);chmax(dp[1][i + 1], dp[0][i] + B[i]);chmax(dp[1][i + 1], dp[1][i]);chmax(dp[0][i + 1], dp[1][i] - B[i]);}int64_t ans = std::max(dp[0][N], dp[1][N]);std::cout << ans << "\n";}}int main(){solver::init();while(true){try{solver::solve();}catch(const std::istream::failure &e){break;}}return 0;}