結果

問題 No.2929 Miracle Branch
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-10-15 01:37:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 303 ms / 2,000 ms
コード長 1,926 bytes
コンパイル時間 2,515 ms
コンパイル使用メモリ 216,332 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 01:37:24
合計ジャッジ時間 13,433 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 3 ms
5,248 KB
testcase_03 AC 3 ms
5,248 KB
testcase_04 AC 3 ms
5,248 KB
testcase_05 AC 3 ms
5,248 KB
testcase_06 AC 3 ms
5,248 KB
testcase_07 AC 3 ms
5,248 KB
testcase_08 AC 3 ms
5,248 KB
testcase_09 AC 4 ms
5,248 KB
testcase_10 AC 4 ms
5,248 KB
testcase_11 AC 4 ms
5,248 KB
testcase_12 AC 3 ms
5,248 KB
testcase_13 AC 4 ms
5,248 KB
testcase_14 AC 3 ms
5,248 KB
testcase_15 AC 3 ms
5,248 KB
testcase_16 AC 4 ms
5,248 KB
testcase_17 AC 4 ms
5,248 KB
testcase_18 AC 6 ms
5,248 KB
testcase_19 AC 7 ms
5,248 KB
testcase_20 AC 9 ms
5,248 KB
testcase_21 AC 15 ms
5,248 KB
testcase_22 AC 4 ms
5,248 KB
testcase_23 AC 25 ms
5,248 KB
testcase_24 AC 83 ms
5,248 KB
testcase_25 AC 12 ms
5,248 KB
testcase_26 AC 4 ms
5,248 KB
testcase_27 AC 4 ms
5,248 KB
testcase_28 AC 3 ms
5,248 KB
testcase_29 AC 3 ms
5,248 KB
testcase_30 AC 3 ms
5,248 KB
testcase_31 AC 3 ms
5,248 KB
testcase_32 AC 3 ms
5,248 KB
testcase_33 AC 3 ms
5,248 KB
testcase_34 AC 273 ms
5,248 KB
testcase_35 AC 265 ms
5,248 KB
testcase_36 AC 3 ms
5,248 KB
testcase_37 AC 269 ms
5,248 KB
testcase_38 AC 267 ms
5,248 KB
testcase_39 AC 270 ms
5,248 KB
testcase_40 AC 271 ms
5,248 KB
testcase_41 AC 281 ms
5,248 KB
testcase_42 AC 279 ms
5,248 KB
testcase_43 AC 303 ms
5,248 KB
testcase_44 AC 274 ms
5,248 KB
testcase_45 AC 4 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

vector<bool> prime;

void erat(ll N){
    prime.resize(N+1, 1);
    prime[0] = 0;
    prime[1] = 0;
    for (ll i=2; i*i<=N; i++){
        if (prime[i]){
            for (ll j=i*2; j <= N; j+=i){
                prime[j] = 0;
            }
        }
    }
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    /*
       4は2*2に分解しない方がいい
       6以上は分解した方がいい。
    */

    ll X, N=2e5, ng=0, nb=0, x, y;
    cin >> X;
    if (X == 1){
        cout << 2 << endl;
        cout << 1 << " " << 2 << endl;
        cout << 'b' << " " << 'g' << endl;
        return 0;
    }
    vector<ll> v; //茶色の頂点の番号
    map<ll, ll> mp;
    erat(N);
    for (int i=2; i<=N; i++){
        if (!prime[i]) continue;
        while(X % i == 0){
            X /= i;
            mp[i]++;
        }
    }

    if (X > N){
        cout << -1 << endl;
        return 0;
    }

    x = mp[2];
    y = x/2;
    //4がy個
    for (int i=0; i<y; i++){
        nb++;
        v.push_back(ng+nb);
        ng += 4;
    }
    if (x % 2 == 1){
        nb++;
        v.push_back(ng+nb);
        ng += 2;
    }
    for (auto [x, y] : mp){
        if (x == 2) continue;
        for (int i=0; i<y; i++){
            nb++;
            v.push_back(ng+nb);
            ng += x;
        }
    }
    v.push_back(nb+ng+1);
    if (nb+ng > N){
        cout << -1 << endl;
        return 0;
    }

    cout << nb+ng << endl;
    for (int i=0; i<v.size()-1; i++){
        for (int j=v[i]+1; j<=v[i+1]-1; j++){
            cout << v[i] << " " << j << endl;
        }
        if (i != v.size()-2) cout << v[i] << " " << v[i+1] << endl;
    }

    for (int i=0; i<v.size()-1; i++){
        cout << "b ";
        for (int j=v[i]+1; j<=v[i+1]-1; j++){
            cout << "g ";
        }
    }
    cout << endl;

    return 0;
}
0