結果
問題 | No.2929 Miracle Branch |
ユーザー |
![]() |
提出日時 | 2024-10-05 17:52:20 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 1,282 bytes |
コンパイル時間 | 12,673 ms |
コンパイル使用メモリ | 401,656 KB |
実行使用メモリ | 13,568 KB |
最終ジャッジ日時 | 2024-10-12 08:46:06 |
合計ジャッジ時間 | 20,263 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
use proconio::input; use proconio::fastout; #[fastout] #[allow(non_snake_case)] fn main() { input! { mut X: usize, } assert!(1 <= X && X <= 1_000_000_000_000_000_000); if X == 1 { println!("2"); println!("1 2"); println!("b g"); return; } let n = (X as f64).sqrt() as usize; let mut p = Vec::new(); while X % 4 == 0 { p.push(4); X /= 4; } for i in 2..=n { if i >= 200000 { if X == 1 { break; } println!("-1"); return; } while X % i == 0 { p.push(i); X /= i; } } if X > 1 { p.push(X); } let N = p.len(); let s = p.iter().sum::<usize>(); if N + s > 200_000 { println!("-1"); return; } println!("{}", N + s); let mut j = N; for i in 0..N { for _ in 0..p[i] { println!("{} {}", i+1, j+1); j += 1; } if i < N - 1 { println!("{} {}", i+1, i+2); } } println!("{} {}", "b".repeat(N).chars().map(|x| x.to_string()).collect::<Vec<String>>().join(" "), "g".repeat(s).chars().map(|x| x.to_string()).collect::<Vec<String>>().join(" ")); }