結果

問題 No.2567 A_1 > A_2 > ... > A_N
ユーザー gabriel55_gabriel55_
提出日時 2023-12-02 17:41:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 2,508 bytes
コンパイル時間 2,425 ms
コンパイル使用メモリ 204,976 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-02 17:41:36
合計ジャッジ時間 4,752 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#if !__INCLUDE_LEVEL__
#include __FILE__

void solve() {
   ll n, x;
   cin >> n >> x;
   vector<ll> a(n+1);
   bool ok = true;
   m_99(i,1,n) {
      a[i] = i;
      x -= a[i];
      if(x < 0) ok = false;
   }
   a[n] = x;
   if(x < 0 || a[n-1] >= a[n]) ok = false;
   if(!ok) {
      cout << -1 << '\n';
      return;
   }
   reverse(a.begin(), a.end());
   if(n == 1) {
      cout << a[0] << '\n';
      return;
   }
   auto check = [&](ll m) -> bool {
      double X = m;
      if(X*(n-1) > 4e18) return false;
      return true;
   };
   {
      ll ook = 0, ng = 1e18;
      while(abs(ook - ng) > 1) {
         ll m = (ook + ng) / 2;
         if(check(m) && a[0]-(n-1)*m > a[1]+m) ook = m;
         else ng = m;
      }
      a[0] -= ook * (n-1);
      m_99(i,1,n) a[i] += ook;
   }
   m_99(i,1,n) {
      if(a[0]-1 > a[i]+1 && a[0]-1 > a[1]) {
         a[0]--;
         a[i]++;
      } else break;
   }
   rep(i,n) cout << a[i] << " \n"[i == n-1];
}

int main() {
   ll t;
   cin >> t;
   while(t--) {
      solve();
   }
}

/*---------------------------------------------------------------------------------------------------
      ○______
       ||      |
       ||   ●   |
       ||      |
        || ̄ ̄ ̄ ̄ ̄
       ||  君が代は
   ∧__,,∧||  千代に八千代に
  ( `・ω・||    さざれ石の巌となりて
   ヽ  つ0     こけのむすまで
   し―-J
---------------------------------------------------------------------------------------------------*/

#else
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ldb = long double;
using P = pair<ll, ll>;
#define fi first
#define se second
#define m_99(i,a,b) for (ll i = a, i##_range = (b); i < i##_range; i++)
#define REP(i,a,b) m_99(i,a,b)
#define rep(i,a) m_99(i,0,a)
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }
#ifdef _DEBUG
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif
struct initialise { initialise() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }__INI__;
const ll inf = 1LL << 60;
const ll dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
#endif
0