結果

問題 No.1172 Add Recursive Sequence
ユーザー noshi91noshi91
提出日時 2020-05-09 18:19:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,401 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 74,752 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 06:57:20
合計ジャッジ時間 1,794 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 RE -
testcase_17 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <limits>

namespace checker {

using imax = std::intmax_t;

std::string c_to_str(const int c) {
  if (c == '\n') {
    return "'\\n'";
  }
  if (c == std::char_traits<char>::eof()) {
    return "eof";
  }
  return std::string({'\'', char(c), '\''});
}

int scan_char() { return std::cin.get(); }
bool is_digit(const int c) { return '0' <= c && c <= '9'; }
int to_num(const int c) { return c - '0'; }

imax scan_imax(const int end) {
  if (is_digit(end)) {
    std::cerr << "end must not be digit" << std::endl;
    std::abort();
  }
  imax ret = 0;
  bool negative = false;
  int c = scan_char();
  if (c == '-') {
    negative = true;
    c = scan_char();
  }
  if (!is_digit(c)) {
    std::cerr << "no digits" << std::endl;
    std::abort();
  }
  if (c == '0') {
    if (negative) {
      std::cerr << "found -0" << std::endl;
      std::abort();
    }
    c = scan_char();
    if (is_digit(c)) {
      std::cerr << "leading zeros" << std::endl;
      std::abort();
    }
    if (c != end) {
      std::cerr << "expected " << c_to_str(end) << ", found " << c_to_str(c)
                << std::endl;
      std::abort();
    }
    return 0;
  }
  while (is_digit(c)) {
    c = to_num(c);
    if (ret > (std::numeric_limits<imax>::max() - c) / 10) {
      std::cerr << "overflow" << std::endl;
      std::abort();
    }
    ret = ret * 10 + c;
    c = scan_char();
  };
  if (c != end) {
    std::cerr << "expected " << c_to_str(end) << ", found " << c_to_str(c)
              << std::endl;
    std::abort();
  }
  if (negative) {
    ret = -ret;
  }
  return ret;
}

constexpr int eof = std::char_traits<char>::eof();

void check() {
  imax k = scan_imax(' ');
  assert(1 <= k && k <= 10);

  imax n = scan_imax(' ');
  assert(1 <= n && n <= 200000);

  imax m = scan_imax('\n');
  assert(1 <= m && m <= 200000);

  for (imax i = 0; i < k; ++i) {
    imax a = scan_imax(" \n"[i + 1 == k]);
    assert(-1000000000 <= a && a <= 1000000000);
  }

  for (imax i = 0; i < k; ++i) {
    imax c = scan_imax(" \n"[i + 1 == k]);
    assert(-1000000000 <= c && c <= 1000000000);
  }

  for (imax i = 0; i < m; ++i) {
    imax l = scan_imax(' ');
    imax r = scan_imax('\n');
    assert(0 <= l && l < r && r <= n);
  }

  assert(scan_char() == eof);
}

} // namespace checker

int main() {
  checker::check();
  return 0;
}
0