結果

問題 No.2929 Miracle Branch
ユーザー hirakuuuuhirakuuuu
提出日時 2024-10-12 17:09:29
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,016 bytes
コンパイル時間 3,242 ms
コンパイル使用メモリ 250,844 KB
実行使用メモリ 12,064 KB
最終ジャッジ日時 2024-10-12 17:09:41
合計ジャッジ時間 6,879 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, a, n) for(ll i = a; i < n; i++)
#define rrep(i, a, n) for(int i = a; i >= n; i--)
#define inr(l, x, r) (l <= x && x < r)
#define ll long long
#define ld long double

// using mint = modint1000000007;
// using mint = modint998244353;
constexpr int IINF = 1001001001;
constexpr ll INF = 1e18;

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    ll x; cin >> x;
    if(x == 1){
        cout << "2" << endl;
        cout << "1 2" << endl;
        cout << "b g" << endl;
        return 0;
    }

    vector<ll> yakusu;
    rep(i, 2, 200000){
        if(x%i == 0) yakusu.push_back(i);
    }
    int m = (int)yakusu.size();

    vector<ll> p, q;
    ll sum_q = 0, sum_p = 200001;
    ll score_p = 200001, score_q = 0;
    auto f = [&](auto self, ll y, int pos=0) -> void {
        if(y == 1){
            if(score_p > score_q){
                p = q;
                sum_p = sum_q;
                score_p = score_q;
            }
            return;
        }

        rep(id, pos, m){
            ll i = yakusu[id];
            if(i > y || score_q+(i+1) >= score_p) break;
            if(y%i == 0){
                q.push_back(i);
                sum_q += i;
                score_q += i+1;
                self(self, y/i, id);
                q.pop_back();
                sum_q -= i;
                score_q -= i+1;
            }
        }
    };

    f(f, x);
    if(sum_p > 200000LL){
        cout << -1 << endl;
        return 0;
    }
    int n = (int)p.size();
    cout << sum_p+n << endl;
    int adj = n+1;
    rep(i, 0, n){
        if(i > 0) cout << i << ' ' << i+1 << endl;
        rep(j, 0, p[i]){
            cout << i+1 << ' ' << adj++ << endl;
        }
    }
    rep(i, 0, n){
        cout << 'b' << ' ';
    }
    rep(i, 0, sum_p){
        cout << 'g' << ' ';
    }
    cout << endl;

    
    return 0;
}
0