結果
| 問題 |
No.2929 Miracle Branch
|
| コンテスト | |
| ユーザー |
Ayuna
|
| 提出日時 | 2024-10-19 16:44:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 288 ms / 2,000 ms |
| コード長 | 1,830 bytes |
| コンパイル時間 | 1,044 ms |
| コンパイル使用メモリ | 82,552 KB |
| 最終ジャッジ日時 | 2025-02-24 21:35:34 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <cassert>
using namespace std;
using ll = long long;
int main(){
const ll mx = 200'000;
ll x;
cin >> x;
if (x == 1){
cout << 2 << endl;
cout << "1 2" << endl;
cout << "b g" << endl;
return 0;
}
map<ll, ll> cnt;
for(ll i = 2; i <= mx; i++){
if (i * i > x) break;
while(x % i == 0){
x /= i;
cnt[i]++;
}
}
if (x <= mx && x != 1) {
cnt[x]++;
x = 1;
}
if(x > 1) {
cout << -1 << endl;
return 0;
}
ll n = 0;
ll b = 0;
for(auto p: cnt){
if (p.first == 2){
n += p.second / 2 * 5;
b += p.second / 2;
n += p.second % 2 * 3;
b += p.second % 2;
}
else{
n += p.second * (p.first + 1);
b += p.second;
}
if (n > mx){
cout << -1 << endl;
return 0;
}
}
cout << n << endl;
for (int i = 0; i < b - 1; i++){
cout << i + 1 << " " << i + 2 << endl;
}
int g = 0;
int useb = 0;
for(auto p: cnt){
if (p.first == 2){
for (int i = 0; i < p.second / 2; i++){
for (int j = 0; j < 4; j++){
cout << useb + 1 << " " << b + g + 1 << endl;
g++;
}
useb++;
}
for (int i = 0; i < p.second % 2; i++){
for (int j = 0; j < 2; j++){
cout << useb + 1 << " " << b + g + 1 << endl;
g++;
}
useb++;
}
}
else{
for (int i = 0; i < p.second; i++){
for (int j = 0; j < p.first; j++){
cout << useb + 1 << " " << b + g + 1 << endl;
g++;
}
useb++;
}
}
}
assert(b == useb);
assert(b + g == n);
for (int i = 0; i < b; i++){
cout << "b ";
}
for(int i = 0; i < n - b; i++){
if (i != n - b - 1) cout << "g ";
else cout << "g" << endl;
}
}
Ayuna