結果

問題 No.3625 Find Superfibonacci Number
コンテスト
ユーザー tnakao0123
提出日時 2026-08-17 16:48:37
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 910µs
コード長 1,107 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 166 ms
コンパイル使用メモリ 53,072 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-08-17 16:48:39
合計ジャッジ時間 1,486 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3625.cc:  No.3625 Find Superfibonacci Number - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 1000000;

/* typedef */

/* global variables */

int ds[MAX_N];

/* subroutines */

void printds(int l, int ds[]) {
  for (int i = l - 1; i >= 0; i--) putchar('0' + ds[i]);
  putchar('\n');
}

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int k;
    scanf("%d", &k);

    int l = 0;
    for (int r = k; r > 0;) {
      int d = min(9, r);
      ds[l++] = d;
      r -= d;
    }
    //printds(l, ds);

    if (l == 1) {
      ds[2] = k / 2 + 1, ds[1] = 0, ds[0] = k - ds[2];
      l = 3;
    }
    else {
      if (ds[l - 1] == 9) ds[l++] = 0;
      if (l == 2) {
	int d = ds[l - 1] + 9;
	ds[l] = d / 2 + 1, ds[l - 1] = 0, ds[l - 2] = d - ds[l];
	l++;
      }
      else if (ds[l - 1] < 8) {
	ds[l] = ds[l - 1] + 1, ds[l - 1] = 9, ds[l - 2] = 0, ds[l - 3] = 8;
	l++;
      }
      else {
	ds[l] = 9, ds[l - 1] = 0, ds[l - 2] = 8;
	l++;
      }
    }

    printds(l, ds);
  }

  return 0;
}

0