結果

問題 No.1199 お菓子配り-2
コンテスト
ユーザー abc3
提出日時 2020-08-28 22:55:12
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 559 ms / 1,000 ms
コード長 876 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,682 ms
コンパイル使用メモリ 184,152 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2026-05-09 16:56:48
合計ジャッジ時間 15,360 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1000000007;
const int INF=1001001001;

int main() {
  int N,M;
  cin>>N>>M;
  vector<vector<int64_t>>A(N,vector<int64_t>(M));
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin>>A[i][j];
    }
  }
  vector<int64_t>t(N);
  for(int i=0;i<N;i++){
    int64_t sum=0;
    for(int j=0;j<M;j++){
      sum+=A[i][j];
    }
    t[i]=sum;
  }
  
  int64_t ans=0;
  int cnt=1;
  for(int i=0;i<N;i++){
    if((cnt)%2!=0){
      if(t[i+1]<t[i]){ans+=t[i];cnt++;}
    }
    else{
      if(i==N-1){continue;}
      else if(t[i+1]>t[i]){ans-=t[i];cnt++;}
    }
  }
  cout<<ans<<endl;
  return 0;  
}
0