結果
問題 | No.2567 A_1 > A_2 > ... > A_N |
ユーザー | a01sa01to |
提出日時 | 2023-12-02 16:10:29 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 160 ms / 2,000 ms |
コード長 | 1,000 bytes |
コンパイル時間 | 2,250 ms |
コンパイル使用メモリ | 202,512 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-26 19:54:52 |
合計ジャッジ時間 | 4,964 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); ++i) void solve() { ll n, x; cin >> n >> x; if (n * (n + 1) / 2 > x) { cout << -1 << endl; return; } //x <= n*(2l+n-1)/2 // 2x/n <= 2l+n-1 // 2l >= 2x/n - n + 1 // l <= x/n - (n-1)/2 ll l_ok = x / n, l_ng = -1; while (l_ok - l_ng > 1) { assert(l_ok > l_ng); ll l = (l_ok + l_ng) / 2; if (x <= n * (2 * l + n - 1) / 2) { l_ok = l; } else { l_ng = l; } } Debug(l_ok); vector<ll> ans(n); rep(i, n) ans[i] = l_ok + n - i - 1; rep(i, n) x -= ans[i]; assert(x <= 0); assert(x > -n); for (int i = n - 1; i >= 0; --i) { if (x == 0) break; --ans[i], ++x; } assert(x == 0); rep(i, n) cout << ans[i] << " "; cout << endl; } int main() { int t; cin >> t; while (t--) solve(); return 0; }