結果

問題 No.2567 A_1 > A_2 > ... > A_N
ユーザー tnakao0123tnakao0123
提出日時 2023-12-04 01:24:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 947 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 41,920 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-04 01:24:34
合計ジャッジ時間 2,456 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 21 ms
6,676 KB
testcase_02 AC 25 ms
6,676 KB
testcase_03 AC 21 ms
6,676 KB
testcase_04 AC 25 ms
6,676 KB
testcase_05 AC 26 ms
6,676 KB
testcase_06 AC 53 ms
6,676 KB
testcase_07 AC 54 ms
6,676 KB
testcase_08 AC 53 ms
6,676 KB
testcase_09 AC 53 ms
6,676 KB
testcase_10 AC 55 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2567.cc:  No.2567 A_1 > A_2 > ... > A_N - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 200000;
const long long MAX_X = 1000000000000000000LL;

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

inline ll sigma(ll a, int n) {
  return (a - n) * n + (ll)n * (n + 1) / 2;
}

/* main */

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

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

    if (sigma(n, n) > x) { puts("-1"); continue; }

    ll b0 = n - 1, b1 = MAX_X * 2 / n;
    while (b0 + 1 < b1) {
      ll b = (b0 + b1) / 2;
      if (sigma(b, n) >= x) b1 = b;
      else b0 = b;
    }
    //printf("b1=%d\n", b1);

    ll ai = b1;
    for (int i = 0; i < n; i++) {
      while (sigma(ai - 1, n - i) >= x) ai--;
      x -= ai;
      printf("%lld%c", ai, (i + 1 < n) ? ' ' : '\n');
    }
  }

  return 0;
}
0