結果

問題 No.2771 Personal Space
ユーザー 👑 AngrySadEightAngrySadEight
提出日時 2024-05-27 18:41:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 1,619 bytes
コンパイル時間 1,145 ms
コンパイル使用メモリ 94,480 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-05-27 18:41:41
合計ジャッジ時間 5,904 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 66 ms
8,952 KB
testcase_02 AC 67 ms
8,956 KB
testcase_03 AC 69 ms
8,952 KB
testcase_04 AC 70 ms
8,824 KB
testcase_05 AC 68 ms
8,952 KB
testcase_06 AC 67 ms
9,984 KB
testcase_07 AC 52 ms
6,940 KB
testcase_08 AC 251 ms
6,940 KB
testcase_09 AC 51 ms
6,940 KB
testcase_10 AC 62 ms
6,940 KB
testcase_11 AC 66 ms
7,936 KB
testcase_12 AC 66 ms
8,288 KB
testcase_13 AC 53 ms
6,940 KB
testcase_14 AC 53 ms
6,944 KB
testcase_15 AC 57 ms
6,944 KB
testcase_16 AC 58 ms
6,940 KB
testcase_17 AC 60 ms
6,944 KB
testcase_18 AC 53 ms
6,940 KB
testcase_19 AC 50 ms
6,944 KB
testcase_20 AC 69 ms
7,920 KB
testcase_21 AC 64 ms
8,484 KB
testcase_22 AC 68 ms
7,924 KB
testcase_23 AC 70 ms
8,768 KB
testcase_24 AC 74 ms
8,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main() {
    ll T;
    cin >> T;
    while (T--) {
        ll N, M;
        cin >> N >> M;
        vector<ll> ans(N, -1);
        ans[M - 1] = 1;
        // 距離を優先度付きキューによって管理する
        priority_queue<tuple<ll, ll, ll>> pque;
        if (M != 1) {
            pque.push(tuple<ll, ll, ll>(M - 1, M - 2, 2 * (M - 1)));
        }
        if (M != N) {
            pque.push(tuple<ll, ll, ll>(N - M, -M, 2 * (N - M)));
        }
        for (ll i = 2; i <= N; i++) {
            ll half_ps, px, ps;
            tie(half_ps, px, ps) = pque.top();
            pque.pop();
            px *= -1;
            // cout << half_ps << " " << px << " " << ps << endl;
            ans[px + ps / 2 - 1] = i;
            if (px >= 1) {
                if (ps / 2 > 1) {
                    // cout << px << " " << ps / 2 << endl;
                    pque.push(tuple<ll, ll, ll>((ps / 2) / 2, -px, ps / 2));
                }
            }
            if (px + ps <= N) {
                if ((ps + 1) / 2 > 1) {
                    // cout << px + ps / 2 << " " << (ps + 1) / 2 << endl;
                    pque.push(tuple<ll, ll, ll>(((ps + 1) / 2) / 2,
                                                -(px + ps / 2), (ps + 1) / 2));
                }
            }
            // cout << endl;
        }
        for (ll i = 0; i < N; i++) {
            cout << ans[i] << " ";
        }
        cout << endl;
    }
}
0