結果
問題 | No.2567 A_1 > A_2 > ... > A_N |
ユーザー | t98slider |
提出日時 | 2023-12-02 15:47:41 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 79 ms / 2,000 ms |
コード長 | 1,282 bytes |
コンパイル時間 | 2,103 ms |
コンパイル使用メモリ | 202,096 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-26 19:18:15 |
合計ジャッジ時間 | 4,358 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } template<typename T> T MUL(T a, T b){ T res; return __builtin_mul_overflow(a, b, &res)? std::numeric_limits<T>::max() : res; } long long arith_sum1(long long fst, long long n, long long d){ return MUL(n, MUL(2ll, fst) + MUL(n - 1, d)) / 2; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ ll n, x; cin >> n >> x; if(x < n * (n + 1) / 2){ cout << -1 << '\n'; continue; } auto f = [&](ll v){ return MUL(v, v + 1) / 2; }; vector<ll> ans(n); for(int i = 0; i < n; i++){ ll ng = 0, ok = x, mid; ll r = (n - i) * (n - i - 1) / 2; while(ng + 1 < ok){ mid = (ok + ng) / 2; if(x - mid <= arith_sum1(mid - 1, n - i - 1, -1)) ok = mid; else ng = mid; } ans[i] = ok; x -= ok; } cout << ans << '\n'; } }