結果

問題 No.3448 ABBBBBBBBC
コンテスト
ユーザー tnakao0123
提出日時 2026-02-22 15:48:30
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,199 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 460 ms
コンパイル使用メモリ 54,656 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-02-22 15:48:32
合計ジャッジ時間 1,964 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3448.cc:  No.3448 ABBBBBBBBC - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

/* typedef */

using ll = long long;

/* global variables */

/* subroutines */

/* main */

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

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

    bool f = true;
    for (int a = 1; f && a < 10; a++)
      for (int b = 0; f && b < 10; b++)
	if (a != b) {
	  //printf(" a=%d, b=%d, k=%lld\n", a, b, k);
	  
	  // c < b
	  int d0 = (a < b) ? b - 1 : b;
	  ll e0 = (ll)d0 * n;
	  if (k >= e0) k -= e0;
	  else {
	    int l = k / d0 + 1, r = k % d0;
	    int c = 0;
	    while (r > 0) {
	      if (c != a) r--;
	      c++;
	    }
	    if (c == a) c++;
	    printf("%d %d %d %d\n", l + 2, a, b, c);
	    f = false;
	    break;
	  }
	  
	  // c > b
	  int d1 = (a > b) ? 9 - b - 1 : 9 - b;
	  ll e1 = (ll)d1 * n;
	  if (k >= e1) k -= e1;
	  else {
	    int l = n - k / d1, r = k % d1;
	    int c = b + 1;
	    while (r > 0) {
	      if (c != a) r--;
	      c++;
	    }
	    if (c == a) c++;
	    printf("%d %d %d %d\n", l + 2, a, b, c);
	    f = false;
	  }
	}
  }

  return 0;
}

0