結果

問題 No.689 E869120 and Constructing Array 3
ユーザー Pachicobue
提出日時 2018-09-14 17:27:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 30 ms / 1,000 ms
コード長 998 bytes
コンパイル時間 1,613 ms
コンパイル使用メモリ 196,400 KB
最終ジャッジ日時 2025-01-06 13:21:29
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
constexpr int MAX = 1000004;
bool isprime[MAX + 1];
int main()
{
    int K;
    std::cin >> K;
    auto solve = [](int K) {
        std::vector<int> ans;
        if (K == 0) { return ans; }
        const int a = std::sqrt(K), b = K / a;
        for (int i = 0; i < a; i++) { ans.push_back(2); }
        for (int i = 0; i < b; i++) { ans.push_back(5); }
        K -= a * b;
        if (K == 0) { return ans; }
        const int c = std::sqrt(K), d = K / c;
        for (int i = 0; i < c; i++) { ans.push_back(4); }
        for (int i = 0; i < d; i++) { ans.push_back(7); }
        K -= c * d;
        if (K == 0) { return ans; }
        for (int i = 0; i < K; i++) { ans.push_back(20); }
        ans.push_back(23);
        return ans;
    };
    const auto ans = solve(K);
    std::cout << ans.size() << std::endl;
    for (const auto e : ans) { std::cout << e << " "; }
    std::cout << std::endl;
    return 0;
}
0