結果
問題 | No.2929 Miracle Branch |
ユーザー |
|
提出日時 | 2024-10-12 16:33:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 279 ms / 2,000 ms |
コード長 | 956 bytes |
コンパイル時間 | 1,770 ms |
コンパイル使用メモリ | 171,292 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-12 16:34:05 |
合計ジャッジ時間 | 10,333 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin >> n; if(n == 1) { cout << 2 << endl; cout << 1 << ' ' << 2 << endl; cout << 'b' << ' ' << 'g' << endl; return 0; } vector<int> s; int d = 0; while(n%2 == 0) { n/=2; d++; } if(d%2 == 1) s.push_back(2), d--; while(d > 0) { s.push_back(4); d-=2; } for(int i = 3; i <= 200000; i++) while(n%i == 0) { n/=i; s.push_back(i); } if(n != 1) { cout << -1 << endl; return 0; } int m = 0; int l = s.size(); for(int i = 0; i < l; i++) m+=s[i]; if(l+m > 200000) { cout << -1 << endl; return 0; } cout << m+l << endl; for(int i = 0; i < l-1; i++) cout << i+1 << ' ' << i+2 << endl; int e = l; for(int i = 0; i < l; i++) { for(int j = 0; j < s[i]; j++) { cout << i+1 << ' ' << e+1 << endl; e++; } } for(int i = 0; i < l; i++) cout << 'b' << ' '; for(int i = 0; i < m; i++) cout << 'g' << ' '; cout << endl; }