結果
| 問題 | No.2929 Miracle Branch |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-10-14 15:58:01 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 1,043 bytes |
| 記録 | |
| コンパイル時間 | 258 ms |
| コンパイル使用メモリ | 71,736 KB |
| 実行使用メモリ | 9,228 KB |
| 最終ジャッジ日時 | 2026-07-05 23:27:26 |
| 合計ジャッジ時間 | 10,756 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 2929.cc: No.2929 Miracle Branch - yukicoder
*/
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 200000;
/* typedef */
using ll = long long;
using vi = vector<int>;
/* global variables */
/* subroutines */
/* main */
int main() {
ll x;
scanf("%lld", &x);
vi vs;
if (x <= 4) vs.push_back(x);
else {
while (x % 4 == 0) vs.push_back(4), x /= 4;
for (int i = 2; x > 1 && i <= MAX_N; i++)
while (x % i == 0)
vs.push_back(i), x /= i;
if (x > 1) { puts("-1"); return 0; }
}
ll sum = 0;
for (auto v: vs) sum += v + 1;
if (sum > MAX_N) { puts("-1"); return 0; }
int m = vs.size(), n = sum;
printf("%d\n", n);
for (int i = 0; i + 1 < m; i++) printf("%d %d\n", i + 1, i + 2);
for (int i = 0, k = m; i < m; i++)
for (int j = 0; j < vs[i]; j++)
printf("%d %d\n", i + 1, (k++) + 1);
for (int i = 0; i < n; i++)
printf("%c%c", (i < m) ? 'b' : 'g', (i + 1 < n) ? ' ' : '\n');
return 0;
}
tnakao0123