結果

問題 No.2567 A_1 > A_2 > ... > A_N
ユーザー t98slidert98slider
提出日時 2023-12-02 15:47:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,282 bytes
コンパイル時間 1,879 ms
コンパイル使用メモリ 203,692 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-02 15:47:46
合計ジャッジ時間 3,937 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 57 ms
6,548 KB
testcase_02 AC 70 ms
6,676 KB
testcase_03 AC 55 ms
6,676 KB
testcase_04 AC 70 ms
6,676 KB
testcase_05 AC 73 ms
6,676 KB
testcase_06 AC 34 ms
6,676 KB
testcase_07 AC 35 ms
6,676 KB
testcase_08 AC 34 ms
6,676 KB
testcase_09 AC 35 ms
6,676 KB
testcase_10 AC 36 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 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
    }
}
0