結果

問題 No.45 回転寿司
ユーザー hitoyozakehitoyozake
提出日時 2020-03-01 16:37:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,097 bytes
コンパイル時間 783 ms
コンパイル使用メモリ 73,344 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 22:18:30
合計ジャッジ時間 1,905 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>

void debug(int a, int b, int tmp, int tmppre){
  std::cout << "a: " << a << ", b:" << b << ", tmp:" << tmp << ", tmppre: " << tmppre << std::endl;
}

int main(){

  int n = 0;

  std::cin >> n;

  int a = 0, b = 0;
  //aは前に取った場合,bは前に取らなかった場合
  int tmppre = 0; //1つ前の値
  std::string s;
  int gmax = 0, ngmax = 0;
  int pregmax = 0;
  for( int i = 0; i < n; ++i ){
    int tmp = 0;
    std::cin >> tmp;

    //取った場合の最大値
    //取らなかった場合の最大値
    // 取った場合の最大値 < 取らなかった場合の最大値
    //  -> 取った場合の最大値に取らなかった場合maxを代入
    // 取る場合は取らなかった場合最大値に取った値を代入
    // 取らない場合はとった場合最大値で代入

  gmax = ngmax + tmp;

  ngmax = std::max(pregmax, ngmax);

  if(gmax < ngmax){
    gmax = ngmax;
  }

  pregmax = gmax;



  }

  int out = std::max(gmax, pregmax);

  std::cout << out << std::endl;

  return 0;
}
0