提出 #75914275


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n;
    cin >> n;

    // 无解的情况:2, 3, 5
    if (n == 2 || n == 3 || n == 5) {
        cout << "No\n";
        return;
    }

    // 平凡情况
    if (n == 1) {
        cout << "Yes\n1\n";
        return;
    }
    if (n == 4) {
        cout << "Yes\n2 2 2 2\n";
        return;
    }

    // 对于 n >= 6,寻找 c ∈ [0, 4] 使得 n = 4 + 2c + 3k
    int c = -1;
    for (int tc = 0; tc <= 4; ++tc) {
        if (n >= 4 + 2 * tc && (n - 4 - 2 * tc) % 3 == 0) {
            c = tc;
            break;
        }
    }
    // 由理论保证 c 一定存在
    int k = (n - 4 - 2 * c) / 3;

    // 最小堆,用来每次选择最小的数进行 +3 操作(分裂为四个 2x)
    priority_queue<int, vector<int>, greater<int>> pq;

    // 初始序列
    for (int i = 0; i < 4 - c; ++i) pq.push(2);       // 剩余的 2
    for (int i = 0; i < 2 * c; ++i) pq.push(3);       // 由 2 -> 3,3,6 产生的 3
    for (int i = 0; i < c; ++i) pq.push(6);           // 由 2 -> 3,3,6 产生的 6

    // 执行 k 次 +3 操作
    while (k--) {
        int x = pq.top(); pq.pop();
        pq.push(2 * x); pq.push(2 * x);
        pq.push(2 * x); pq.push(2 * x);
    }

    // 输出答案
    cout << "Yes\n";
    while (!pq.empty()) {
        cout << pq.top();
        pq.pop();
        if (!pq.empty()) cout << ' ';
    }
    cout << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}

提出情報

提出日時
問題 A - Sum of Reciprocals of Squares
ユーザ zkl018
言語 C++23 (GCC 15.2.0)
得点 600
コード長 1626 Byte
結果 AC
実行時間 7 ms
メモリ 4024 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 1
AC × 24
セット名 テストケース
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3572 KiB
01_random_00.txt AC 5 ms 3628 KiB
01_random_01.txt AC 5 ms 3520 KiB
01_random_02.txt AC 5 ms 3712 KiB
01_random_03.txt AC 7 ms 3936 KiB
01_random_04.txt AC 7 ms 3924 KiB
01_random_05.txt AC 7 ms 3872 KiB
01_random_06.txt AC 7 ms 3928 KiB
01_random_07.txt AC 7 ms 3980 KiB
01_random_08.txt AC 7 ms 3852 KiB
01_random_09.txt AC 7 ms 3880 KiB
01_random_10.txt AC 7 ms 4024 KiB
01_random_11.txt AC 7 ms 3932 KiB
01_random_12.txt AC 7 ms 3880 KiB
01_random_13.txt AC 7 ms 3940 KiB
01_random_14.txt AC 7 ms 3936 KiB
01_random_15.txt AC 7 ms 3952 KiB
01_random_16.txt AC 7 ms 3924 KiB
01_random_17.txt AC 7 ms 3852 KiB
01_random_18.txt AC 7 ms 3840 KiB
01_random_19.txt AC 7 ms 3984 KiB
01_random_20.txt AC 7 ms 3932 KiB
01_random_21.txt AC 7 ms 3876 KiB
01_random_22.txt AC 7 ms 3912 KiB