結果

問題 No.689 E869120 and Constructing Array 3
ユーザー mamekinmamekin
提出日時 2018-05-19 10:57:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,721 bytes
コンパイル時間 1,195 ms
コンパイル使用メモリ 109,348 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 23:39:45
合計ジャッジ時間 3,802 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

void findPrime(int N, vector<bool>& isPrime)
{
    isPrime.assign(N+1, true);
    isPrime[0] = isPrime[1] = false;
    for(int i=2; i*i<=N; i++){
        if(isPrime[i]){
            for(int j=i; i*j<=N; j++){
                isPrime[i*j] = false;
            }
        }
    }
}

const int MAX = 1000000;
const int SIZE = 250;

void solve(int k, vector<int>& ans)
{
    vector<bool> isPrime;
    findPrime(2*MAX, isPrime);

    for(int a=0; ; ++a){
        for(int b=1; ; ++b){
            int n = a * (a - 1) / 2 + a * b;
            if(k < n)
                break;

            int c = (k - n) / b;
            int d = (k - n) % b;
            if(a + b + c + d <= SIZE){
                const int x[] = {1, 2, 3, 5};
                const int y[] = {a, b, c, d};
                ans.clear();
                for(int i=0; i<4; ++i){
                    for(int j=0; j<y[i]; ++j){
                        ans.push_back(x[i]);
                    }
                }
                return;
            }
        }
    }
}

int main()
{
    int k;
    cin >> k;

    vector<int> v;
    solve(k, v);

    int n = v.size();
    cout << n << endl;
    cout << v[0];
    for(int i=1; i<n; ++i)
        cout << ' ' << v[i];
    cout << endl;

    return 0;
}
0