結果

問題 No.3062 A + B
ユーザー risujirohrisujiroh
提出日時 2020-04-01 21:55:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,882 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 166,920 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-09 18:05:37
合計ジャッジ時間 2,290 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:38:19: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   38 | __int128_t digits(auto& i) {
      |                   ^~~~
main.cpp:43:17: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   43 | __int128_t expr(auto& i);
      |                 ^~~~
main.cpp:44:16: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   44 | __int128_t num(auto& i) {
      |                ^~~~
main.cpp:55:17: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   55 | __int128_t term(auto& i) {
      |                 ^~~~
main.cpp:63:17: 警告: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
   63 | __int128_t expr(auto& i) {
      |                 ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

char readchar() {
  static char buf[1 << 15], *ptr = buf, *end = buf;
  if (ptr == end) ptr = buf, end = buf + fread(buf, 1, 1 << 15, stdin);
  return *ptr++;
}
void writechar(char c = 0) {
  static char buf[1 << 15], *ptr = buf;
  if (ptr == end(buf) or c == 0) fwrite(buf, 1, ptr - buf, stdout), ptr = buf;
  *ptr++ = c;
}
template <class Z = int> Z getint() {
  char c = readchar();
  bool neg = c == '-';
  Z res = neg ? 0 : c - '0';
  while (isdigit(c = readchar())) res = res * 10 + (c - '0');
  return neg ? -res : res;
}
template <class Z> void putint(Z a, char delim = '\n') {
  if (a < 0) writechar('-'), a = -a;
  int d[40], i = 0;
  do d[i++] = a % 10; while (a /= 10);
  while (i--) writechar('0' + d[i]);
  writechar(delim);
}
string getstring(char delim = '\n') {
  string res;
  for (char c; (c = readchar()) != delim; ) res += c;
  return res;
}
void putstring(string s, char delim = '\n') {
  for (char c : s) writechar(c);
  writechar(delim);
}

__int128_t digits(auto& i) {
  __int128_t res = 0;
  while (isdigit(*i)) res = 10 * res + *i++ - '0';
  return res;
}
__int128_t expr(auto& i);
__int128_t num(auto& i) {
  switch (*i) {
    case '+': return num(++i);
    case '-': return -num(++i);
    case '(': {
      __int128_t res = expr(++i);
      return ++i, res;
    }
    default: return digits(i);
  }
}
__int128_t term(auto& i) {
  __int128_t res = num(i);
  while (true) switch (*i) {
    case '*': res *= num(++i); break;
    case '/': res /= num(++i); break;
    default: return res;
  }
}
__int128_t expr(auto& i) {
  __int128_t res = term(i);
  while (true) switch (*i) {
    case '+': res += term(++i); break;
    case '-': res -= term(++i); break;
    default: return res;
  }
}

int main() {
  string s = getstring(' ');
  s += getstring();
  auto it = begin(s);
  putint(expr(it));
  writechar();
}
0