結果
問題 |
No.2929 Miracle Branch
|
ユーザー |
![]() |
提出日時 | 2024-10-13 16:35:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 294 ms / 2,000 ms |
コード長 | 1,045 bytes |
コンパイル時間 | 2,205 ms |
コンパイル使用メモリ | 200,288 KB |
最終ジャッジ日時 | 2025-02-24 19:17:44 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); long long x; cin >> x; if (x == 1) { cout << "2\n1 2\nb g\n"; return 0; } const int M = 200000; vector<int> pf; for (int i = 2; i <= M; i++) { while (x % i == 0) { pf.push_back(i); x /= i; } } if (x > 1) { cout << -1 << endl; return 0; } vector<pair<int, int>> ans; vector<char> color; int n = 0; int r_prev = 0; for (int i = 0; i < pf.size(); i++) { if (n) { ans.push_back({r_prev, n}); } int r = n++; color.push_back('b'); int cnt = pf[i]; if (i + 1 < pf.size() && pf[i] == 2 && pf[i + 1] == 2) { cnt = 4; i++; } for (int j = 0; j < cnt; j++) { ans.push_back({r, n++}); color.push_back('g'); } r_prev = r; } if (n > M) { cout << -1 << endl; return 0; } cout << n << endl; for (auto [u, v] : ans) { cout << u + 1 << " " << v + 1 << endl; } for (int i = 0; i < n; i++) { cout << color[i] << " "; } cout << endl; }