結果

問題 No.1199 お菓子配り-2
ユーザー motmot
提出日時 2020-08-29 12:48:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 439 ms / 1,000 ms
コード長 1,161 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 84,980 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-26 16:22:22
合計ジャッジ時間 16,233 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 110 ms
5,504 KB
testcase_04 AC 276 ms
8,192 KB
testcase_05 AC 9 ms
5,376 KB
testcase_06 AC 16 ms
5,376 KB
testcase_07 AC 132 ms
5,760 KB
testcase_08 AC 182 ms
6,784 KB
testcase_09 AC 110 ms
5,376 KB
testcase_10 AC 28 ms
5,376 KB
testcase_11 AC 85 ms
5,376 KB
testcase_12 AC 84 ms
5,376 KB
testcase_13 AC 30 ms
5,376 KB
testcase_14 AC 25 ms
5,376 KB
testcase_15 AC 21 ms
5,376 KB
testcase_16 AC 177 ms
6,400 KB
testcase_17 AC 85 ms
5,376 KB
testcase_18 AC 187 ms
6,656 KB
testcase_19 AC 48 ms
5,376 KB
testcase_20 AC 331 ms
9,216 KB
testcase_21 AC 203 ms
7,040 KB
testcase_22 AC 108 ms
5,376 KB
testcase_23 AC 149 ms
6,144 KB
testcase_24 AC 205 ms
7,168 KB
testcase_25 AC 31 ms
5,376 KB
testcase_26 AC 232 ms
7,680 KB
testcase_27 AC 187 ms
6,912 KB
testcase_28 AC 436 ms
11,136 KB
testcase_29 AC 435 ms
11,136 KB
testcase_30 AC 434 ms
11,136 KB
testcase_31 AC 439 ms
11,264 KB
testcase_32 AC 431 ms
11,136 KB
testcase_33 AC 435 ms
11,136 KB
testcase_34 AC 436 ms
11,264 KB
testcase_35 AC 435 ms
11,136 KB
testcase_36 AC 436 ms
11,264 KB
testcase_37 AC 438 ms
11,264 KB
testcase_38 AC 435 ms
11,136 KB
testcase_39 AC 436 ms
11,264 KB
testcase_40 AC 434 ms
11,136 KB
testcase_41 AC 437 ms
11,136 KB
testcase_42 AC 438 ms
11,136 KB
testcase_43 AC 433 ms
11,264 KB
testcase_44 AC 434 ms
11,136 KB
testcase_45 AC 433 ms
11,264 KB
testcase_46 AC 437 ms
11,264 KB
testcase_47 AC 434 ms
11,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  ll tmpA[N][M];
  for(int i=0;i<N;++i) {
    for(int j=0;j<M;++j) {
      cin>>tmpA[i][j];
    }
  }
  vector<ll> A(N);
  for(int i=0;i<N;++i) {
    A[i] = 0;
    for(int j=0;j<M;++j) {
      A[i] += tmpA[i][j];
    }
  }
  if(N==1) {
    cout<<A[0]<<endl;
    return 0;
  }
  bool up;
  ll ans = 0;
  if(A[0]<=A[1]) up = true;
  else {
    up = false;
    ans += A[0];
  }
  for(int i=1;i<N;++i) {
    if(up) {
      if(A[i]>A[i+1]) {
        up = false;
        ans += A[i];
      }
    }
    else {
      if(A[i]<A[i+1]) {
        up = true;
        ans -= A[i];
      }
    }
  }
  if(up) ans += A[N-1];
  cout<<ans<<endl;
}

0