結果
| 問題 | 
                            No.1199 お菓子配り-2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             shauuebbit
                         | 
                    
| 提出日時 | 2020-08-28 21:50:39 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 741 bytes | 
| コンパイル時間 | 1,619 ms | 
| コンパイル使用メモリ | 171,576 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-11-14 03:20:49 | 
| 合計ジャッジ時間 | 5,688 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | WA * 45 | 
ソースコード
#include<bits/stdc++.h>
const long long INF = 1e15;
using namespace std;
template<typename T>
bool chmax(T& a, const T& b){
  if(a < b){
    a = b;
    return true;
  }else return false;
}
int main(){
  int N, M;
  cin >> N >> M;
  
  vector<long long> sum_A(N, 0);
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++){
      int A;
      cin >> A;
      sum_A[i] += A;
    }
  }
  
  vector<vector<long long>> dp(2, vector<long long>(N + 1, -INF));
  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[1][i]);
    
    chmax(dp[0][i + 1], dp[1][i] - sum_A[i]);
    chmax(dp[1][i + 1], dp[0][i] + sum_A[i]);
  }
  
  cout << max(dp[0][N], dp[1][N]) << endl;
  
  return 0;
}
            
            
            
        
            
shauuebbit