結果

問題 No.2929 Miracle Branch
ユーザー GOTKAKO
提出日時 2024-10-12 15:54:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,162 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 200,800 KB
最終ジャッジ日時 2025-02-24 18:16:59
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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

    long long X; cin >> X;
    if(X == 1){
        cout << "2" << endl;
        cout << "1 2" << endl;
        cout << "b g" << endl;
        return 0;
    }
    vector<pair<int,int>> E;
    for(int i=3; i<=200000; i++){
        int e = 0;
        while(X%i == 0) e++,X /= i;
        if(e) E.push_back({i,e});
    }  
    if(X == 2) E.push_back({2,1}),X /= 2;
    if(X > 2){cout << "-1\n"; return 0;}

    int brown = 0;
    long long all = 0;
    for(auto [multi,gs] : E) all += 1LL*multi*gs,brown += gs;
    all += brown;
    if(all > 200000){cout << "-1\n"; return 0;}
    vector<int> par(all);
    for(int i=1; i<brown; i++) par.at(i) = i-1;
    int p = 0,idx = brown;
    for(auto [multi,gs] : E){
        while(gs--){
            for(int i=0; i<multi; i++) par.at(idx++) = p;
            p++;
        }
    }
    cout << all << endl;
    for(int i=1; i<all; i++) cout << par.at(i)+1 << " " << i+1 << "\n";
    cout << "b";
    for(int i=1; i<brown; i++) cout << " b";
    for(int i=brown; i<all; i++) cout << " g";
    cout << endl;

}
0