結果
| 問題 |
No.2929 Miracle Branch
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2024-10-13 18:25:52 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 297 ms / 2,000 ms |
| コード長 | 1,536 bytes |
| コンパイル時間 | 1,168 ms |
| コンパイル使用メモリ | 103,552 KB |
| 実行使用メモリ | 5,356 KB |
| 最終ジャッジ日時 | 2024-10-13 18:26:05 |
| 合計ジャッジ時間 | 10,997 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll x;
cin>>x;
vector<ll> now;
ll cnt = 0;
for(int i = 2;i<=(int)2e5;i++){
while(x%i==0){
if(i==2){
cnt++;
x /= i;
continue;
}
now.push_back(i);
x /= i;
}
}
if(x!=1) now.push_back(x);
while(cnt>0){
if(cnt>=2){
now.push_back(4);
cnt -= 2;
}else{
now.push_back(2);
break;
}
}
if(now.empty()){
now.push_back(x);
}
ll sum = 0;
for(int i = 0;i<now.size();i++) sum += now[i];
sum += now.size();
if(sum>(int)2e5){
cout<<-1<<endl;
return 0;
}
vector<int> u,v;
int nxt = 0;
int prev = -1;
vector<char> ans;
for(int i = 0;i<now.size();i++){
if(prev!=-1){
u.push_back(nxt);
v.push_back(prev);
}
prev = nxt;
nxt++;
ans.push_back('b');
for(int j = 0;j<now[i];j++){
u.push_back(prev);
v.push_back(nxt);
nxt++;
ans.push_back('g');
}
}
cout<<ans.size()<<endl;
for(int i = 0;i<u.size();i++){
cout<<u[i]+1<<" "<<v[i]+1<<endl;
}
for(int i = 0;i<ans.size();i++){
if(i) cout<<" ";
cout<<ans[i];
}
cout<<endl;
}
momoyuu