結果

問題 No.689 E869120 and Constructing Array 3
ユーザー parukiparuki
提出日時 2018-05-20 23:19:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 1,963 bytes
コンパイル時間 2,115 ms
コンパイル使用メモリ 171,264 KB
実行使用メモリ 7,260 KB
最終ジャッジ日時 2023-09-11 00:10:08
合計ジャッジ時間 2,974 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,188 KB
testcase_01 AC 6 ms
7,140 KB
testcase_02 AC 6 ms
7,244 KB
testcase_03 AC 7 ms
6,988 KB
testcase_04 AC 6 ms
7,128 KB
testcase_05 AC 6 ms
7,260 KB
testcase_06 AC 7 ms
7,136 KB
testcase_07 AC 6 ms
7,140 KB
testcase_08 AC 6 ms
7,200 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 6 ms
7,140 KB
testcase_11 AC 6 ms
7,132 KB
testcase_12 AC 6 ms
7,192 KB
testcase_13 AC 7 ms
7,260 KB
testcase_14 AC 6 ms
7,140 KB
testcase_15 AC 6 ms
7,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

vector<bool> sieveFlags(int n) {
    vector<bool> f(n + 1);
    for (int i = 3; i <= n; i += 2)f[i] = true;
    for (int i = 3; (long long)i*i <= n; i += 2) {
        if (f[i])for (int j = i * 3; j <= n; j += i)f[j] = false;
    }
    if (n >= 2)f[2] = true;
    return f;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    const int MA = 1000001;
    auto A = sieveFlags(MA+1000);
    int K;
    cin >> K;
    vi re, used(MA), B;
    for (int a = 2; K > 0; a += 2) {
        bool ok = true;
        each(b, B)if (A[a + b]) {
            ok = false;
            break;
        }
        if (!ok)continue;

        int x = 1;
        for (; (x+1)*(x+1) <= K; ++x);
        for (int b = 3; b < MA; b += 2)if (!used[b] && A[a + b]) {
            ok = true;
            for(int c=2;c<a;c+=2)if(A[b+c]){
                ok = false;
                break;
            }
            if (!ok)continue;
            rep(c, x) {
                re.push_back(a);
                re.push_back(b);
            }
            used[b] = true;
            B.push_back(b);
            K -= x*x;
            break;
        }
    }
    cout << sz(re) << endl;
    rep(a, sz(re))cout << re[a] << (a != sz(re) - 1 ? ' ' : '\n');
}
0