結果

問題 No.689 E869120 and Constructing Array 3
ユーザー merom686merom686
提出日時 2018-05-18 23:03:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,131 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 73,424 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-10 23:09:33
合計ジャッジ時間 2,029 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int k;
    cin >> k;

    if (k == 0) {
        cout << 1 << endl;
        cout << 1 << endl;
        return 0;
    }

    int p[5] = {}, q[5] = { 1, 5, 8, 13, 34 };

    for (;;) {
        int t = p[0] * (p[0] + 1) / 2;
        if (t > k) break;
        p[0]++;
    }
    k -= p[0] * (p[0] - 1) / 2;

    for (;;) {
        int t = (p[1] + 1) * (p[1] + 1);
        if (t > k) break;
        p[1]++;
    }
    p[2] = p[1];
    k -= p[1] * p[2];

    p[3] = 1;
    for (;;) {
        int t = p[3] * (p[4] + 1);
        if (t > k) break;
        p[4]++;
    }
    k -= p[3] * p[4];

    if (k != 0) throw;

    int n = 0;
    for (int i = 0; i < 5; i++) {
        n += p[i];
    }

    cout << n << endl;
    int h = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < p[i]; j++) {
            cout << q[i] << " \n"[h == n - 1];
            h++;
        }
    }

    return 0;
}
0