結果

問題 No.1199 お菓子配り-2
ユーザー HaarHaar
提出日時 2020-08-28 21:37:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 1,000 ms
コード長 1,945 bytes
コンパイル時間 2,713 ms
コンパイル使用メモリ 204,216 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-26 14:30:13
合計ジャッジ時間 10,501 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 3 ms
6,820 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 67 ms
6,944 KB
testcase_04 AC 143 ms
8,832 KB
testcase_05 AC 7 ms
6,944 KB
testcase_06 AC 7 ms
6,944 KB
testcase_07 AC 48 ms
6,940 KB
testcase_08 AC 66 ms
6,940 KB
testcase_09 AC 39 ms
6,940 KB
testcase_10 AC 10 ms
6,944 KB
testcase_11 AC 30 ms
6,944 KB
testcase_12 AC 44 ms
6,944 KB
testcase_13 AC 16 ms
6,944 KB
testcase_14 AC 10 ms
6,940 KB
testcase_15 AC 8 ms
6,940 KB
testcase_16 AC 61 ms
6,940 KB
testcase_17 AC 30 ms
6,940 KB
testcase_18 AC 75 ms
7,168 KB
testcase_19 AC 19 ms
6,940 KB
testcase_20 AC 116 ms
9,216 KB
testcase_21 AC 68 ms
7,552 KB
testcase_22 AC 74 ms
6,940 KB
testcase_23 AC 50 ms
6,940 KB
testcase_24 AC 68 ms
7,040 KB
testcase_25 AC 11 ms
6,944 KB
testcase_26 AC 75 ms
7,424 KB
testcase_27 AC 61 ms
6,944 KB
testcase_28 AC 138 ms
11,008 KB
testcase_29 AC 138 ms
11,264 KB
testcase_30 AC 135 ms
11,136 KB
testcase_31 AC 139 ms
11,136 KB
testcase_32 AC 140 ms
11,008 KB
testcase_33 AC 141 ms
11,136 KB
testcase_34 AC 140 ms
11,136 KB
testcase_35 AC 140 ms
11,136 KB
testcase_36 AC 140 ms
11,008 KB
testcase_37 AC 140 ms
11,136 KB
testcase_38 AC 141 ms
11,264 KB
testcase_39 AC 140 ms
11,136 KB
testcase_40 AC 141 ms
11,136 KB
testcase_41 AC 141 ms
11,008 KB
testcase_42 AC 144 ms
11,264 KB
testcase_43 AC 141 ms
11,008 KB
testcase_44 AC 141 ms
11,264 KB
testcase_45 AC 139 ms
11,136 KB
testcase_46 AC 141 ms
11,136 KB
testcase_47 AC 143 ms
11,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

template <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;
}
0