結果
| 問題 |
No.1243 約数加算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-05 19:16:05 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,432 bytes |
| コンパイル時間 | 12,841 ms |
| コンパイル使用メモリ | 377,168 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-04 06:39:17 |
| 合計ジャッジ時間 | 13,628 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
fn main() {
let mut t = String::new();
std::io::stdin().read_line(&mut t).ok();
let t: usize = t.trim().parse().unwrap();
let queries = (0..t).map(|_| {
let mut temp = String::new();
std::io::stdin().read_line(&mut temp).ok();
let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
(temp[0], temp[1])
})
.collect::<Vec<_>>();
for &(a, b) in queries.iter() {
let bstr = format!("{:b}", b).chars().collect::<Vec<_>>();
let astr = format!("{:b}", a);
let astr = format!("{}{}", "0".repeat(bstr.len()-astr.len()), astr).chars().collect::<Vec<_>>();
let n = bstr.len();
let start = (0..n).filter(|&i| bstr[i] != astr[i]).nth(0).unwrap();
let mut result = vec![];
let mut aval = a;
for i in (start+1..n).rev() {
let idx = n - 1 - i;
if (aval >> idx) & 1 == 1 {
result.push(1usize << idx);
aval += 1usize << idx;
}
}
for i in 0..n {
let idx = n - 1 - i;
if ((aval >> idx) & 1) != ((b >> idx) & 1) {
result.push(1usize << idx);
aval += 1usize << idx;
}
}
println!("{}", result.len());
println!("{}", result.iter().map(|v| v.to_string()).collect::<Vec<_>>().join(" "));
}
}