結果

問題 No.2929 Miracle Branch
ユーザー HIcoder
提出日時 2024-10-13 13:13:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,818 bytes
コンパイル時間 1,350 ms
コンパイル使用メモリ 129,820 KB
最終ジャッジ日時 2025-02-24 19:14:40
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 8 WA * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
using namespace std;
using ll = long long;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,ll> P;
typedef pair<int,P> PP; 
const ll MOD=998244353;
const int dy[]={0,1,0,-1};
const int dx[]={1,0,-1,0};


int main(){
    ll X;
    cin >> X;

    if(X==1){
        cout<<2<<endl;
        cout<<1<<" "<<2<<endl;
        cout<<"b g"<<endl;
        return 0;
    }

    const int MAXV=2*100000;
    map<ll,ll> mp;
    for(ll v=2;v<=MAXV;v++){
        if(X%v==0){
            ll cnt=0;
            while(X%v==0){
                X/=v;
                cnt++;
            }
            mp[v]=cnt;
        }
    }

    ll tmp_v=0;
    for(auto [v,num]:mp){
        tmp_v+=(v+1)*num;
        // cout<<v<<" "<<num<<endl;
    }


    if(mp.size()==0 || X>1 || tmp_v>MAXV){
        //まだXは割り切れないすうがのこっている
        cout<<-1<<endl;
        return 0;
    }
    vector<pair<int,int>> cand;

    map<int,char> mpc;
    int x=1;
    for(auto [v,num]:mp){
        for(int i=0;i<num;i++){
            int t=x;
            mpc[t]='b';
            for(int j=0;j<v;j++){
                x++;
                cand.push_back({t,x});
                mpc[x]='g';
            }
            x++;
        }
    }
    int sz=mp.size();
    cout<<sz<<endl;

    auto ans=cand;


    for(int i=0;i+1<cand.size();i++){
        if(cand[i].first!=cand[i+1].first){
            ans.push_back({cand[i].first,cand[i+1].first});
        }
    }

    for(auto [t,x]:ans){
        cout<<t<<" "<<x<<endl;
    }

    for(int i=1;i<x;i++){
        cout<<mpc[i]<<(i==x-1?'\n':' ');
    }

}
0