結果

問題 No.539 インクリメント
ユーザー むらためむらため
提出日時 2019-01-26 15:14:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,422 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 152,948 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 10:12:23
合計ジャッジ時間 2,537 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 8 ms
4,348 KB
testcase_02 AC 9 ms
4,348 KB
testcase_03 AC 8 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:52:11: warning: ‘char* gets(char*)’ is deprecated [-Wdeprecated-declarations]
     gets(S);
           ^
In file included from /usr/include/c++/8/cstdio:42,
                 from /usr/include/c++/8/x86_64-redhat-linux/bits/stdc++.h:46,
                 from main.cpp:3:
/usr/include/stdio.h:583:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
main.cpp:52:11: warning: ‘char* gets(char*)’ is deprecated [-Wdeprecated-declarations]
     gets(S);
           ^
In file included from /usr/include/c++/8/cstdio:42,
                 from /usr/include/c++/8/x86_64-redhat-linux/bits/stdc++.h:46,
                 from main.cpp:3:
/usr/include/stdio.h:583:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
/tmp/ccK3RATj.o: In function `main':
main.cpp:(.text.startup+0x2e): warning: the `gets' function is dangerous and should not be used.

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include "bits/stdc++.h"

using namespace std;
// #define int long long
#define REPI(i) for (int i = 0;; i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define ALL(a) begin(a), end(a)
#define let const auto
int scan() {
  int result = 0;
  while (true) {
    auto k = getchar_unlocked();
    if (k < '0' || k > '9') return result;
    result = 10 * result + k - '0';
  }
}
char S[100010];
void reduce(int x, int y, int size) {
  if (x == -1) {
    puts(S);
    return;
  }
  let sx = S[x];
  let sy = S[y];
  S[x] = '\0';
  S[y] = '\0';
  fputs(S, stdout);
  S[y] = sy;
  S[x] = sx;
  auto carry = 1;
  FORR(i, x, y + 1) {
    let c = S[i] - '0';
    let d = c + carry;
    if (d < 10) {
      S[i] = "0123456789"[d];
      carry = 0;
    } else {
      S[i] = '0';
      carry = 1;
    }
  }
  if (carry == 1) putchar_unlocked('1');
  puts(S + x);
}
signed main() {
  let n = scan();
  REP(_, n) {
    gets(S);
    auto i = 0;
    auto x = -1;
    auto y = -1;
    auto preIsAlpha = true;
    REPI(i) {
      let k = S[i];
      if (k == '\0') {
        reduce(x, y, i);
        break;
      }
      let isAlpha = k < '0' || '9' < k;
      if (!isAlpha) {
        y = i;
        if (preIsAlpha) x = i;
      }
      preIsAlpha = isAlpha;
    }
  }
}
0