結果

問題 No.3658 Darumaka Number 2
コンテスト
ユーザー nekoti
提出日時 2026-08-30 16:01:09
言語 C
(gcc 15.3.0)
コンパイル:
gcc-15 -O2 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,266 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 146 ms
コンパイル使用メモリ 38,016 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-08-30 16:01:37
合計ジャッジ時間 2,498 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#define _DEBUG 0

#include<stdio.h>
#include<stdbool.h>
#include<string.h>
#include<stdlib.h>
int main(void)
{
  int scan;//scanf警告用
  int ans=0;
  int i, j;
  
  char s[100010];scan=scanf("%s",s);int slen=strlen(s);
  int notindex = -1;
  bool topNG = false;
  bool topNG2 = false;
  int ren4 = 0;
  for(i=0; i<slen; i++)
  {
    if(s[i]-'0' < 4)
    {
      //繰り下げ初登場
      notindex = i-ren4;
      if(i)
      {
        s[i-ren4-1]--;
        if(ren4==i){topNG2=true;break;}
      }
      else if(0==i)topNG=true;
      break;
    }
    if(s[i]-'0' == 4)ren4++;
    else             ren4 = 0;
#if _DEBUG
printf("%d : notindex = %d, topNG = %d, ren4 = %d, topNG2 = %d\n",i,notindex,topNG,ren4,topNG2);
#endif
  }
#if _DEBUG
printf("? %d : notindex = %d, topNG = %d, ren4 = %d, topNG2 = %d\n",i,notindex,topNG,ren4,topNG2);
#endif
  //■出力
  if(topNG2)
  {
    for(i=1; i<slen; i++)
    {
      printf("5");
    }
    return scan-scan;
  }
  
  bool output5 = false;
  for(i=0; i<slen; i++)
  {
    if(!output5)
    {
      if(notindex == i)     output5 = true;
      else if(s[i]-'0' == 4)printf("4");
      else                  printf("5");
    }
    if(topNG){topNG=false;continue;}
    if(output5)printf("5");
  }
  return scan-scan;
}
0