結果

問題 No.2479 Sum of Squares
ユーザー ldsybldsyb
提出日時 2023-09-22 21:29:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 736 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 4,688 ms
コンパイル使用メモリ 261,900 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 21:29:53
合計ジャッジ時間 10,094 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 736 ms
4,376 KB
testcase_04 AC 245 ms
4,380 KB
testcase_05 AC 138 ms
4,380 KB
testcase_06 AC 169 ms
4,380 KB
testcase_07 AC 161 ms
4,376 KB
testcase_08 AC 209 ms
4,376 KB
testcase_09 AC 180 ms
4,376 KB
testcase_10 AC 198 ms
4,380 KB
testcase_11 AC 179 ms
4,376 KB
testcase_12 AC 202 ms
4,376 KB
testcase_13 AC 131 ms
4,376 KB
testcase_14 AC 171 ms
4,376 KB
testcase_15 AC 173 ms
4,376 KB
testcase_16 AC 185 ms
4,380 KB
testcase_17 AC 179 ms
4,376 KB
testcase_18 AC 170 ms
4,380 KB
testcase_19 AC 190 ms
4,376 KB
testcase_20 AC 188 ms
4,376 KB
testcase_21 AC 159 ms
4,380 KB
testcase_22 AC 179 ms
4,380 KB
testcase_23 AC 156 ms
4,380 KB
testcase_24 AC 173 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

int main()
{
    int64_t s;
    cin >> s;

    vector<int64_t> as;

    int64_t x = 1;
    while ((x + 1) * (x + 1) <= s)
    {
        x++;
    }

    while (0 < s)
    {
        while (x * x <= s)
        {
            as.push_back(x * x);
            s -= x * x;
        }

        x = 1;
        while ((x + 1) * (x + 1) <= s)
        {
            x++;
        }
    }

    cout << as.size() << endl;
    for (auto &&a : as)
    {
        cout << a << ' ';
    }
    cout << endl;

    return 0;
}
0