結果

問題 No.1243 約数加算
コンテスト
ユーザー phspls
提出日時 2023-01-16 04:46:01
言語 Rust
(1.99.0 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
WA  
実行時間 -
コード長 1,289 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 9,049 ms
コンパイル使用メモリ 195,792 KB
実行使用メモリ 9,816 KB
最終ジャッジ日時 2026-10-09 13:08:26
合計ジャッジ時間 9,834 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: value assigned to `target` is never read
  --> src/main.rs:31:17
   |
24 |                 target += val;
   |                 ------------- `target` is overwritten here before the previous value is read
...
31 |                 target += val;
   |                 ^^^^^^^^^^^^^ this value is reassigned later and never used
   |
   = note: `#[warn(unused_assignments)]` (part of `#[warn(unused)]`) on by default

ソースコード

diff #
raw source code

fn main() {
    let mut t = String::new();
    std::io::stdin().read_line(&mut t).ok();
    let t: usize = t.trim().parse().unwrap();

    for _ in 0..t {
        let mut ab = String::new();
        std::io::stdin().read_line(&mut ab).ok();
        let ab: Vec<usize> = ab.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let a = ab[0];
        let b = ab[1];
        let mut stack = vec![];

        let astr = format!("{:b}", a).chars().collect::<Vec<_>>();
        let bstr = format!("{:b}", b).chars().collect::<Vec<_>>();
        let limit = bstr.len();
        let limit = if astr.len() == limit { (1..=limit).rev().filter(|&i| astr[limit-i] != bstr[limit-i]).nth(0).unwrap() } else { limit };
        let mut target = a;
        for i in 0..limit-1 {
            if ((target >> i) & 1) == 1 {
                let val = 1usize << i;
                stack.push(val);
                target += val;
            }
        }
        for i in (0..limit-1).rev() {
            if ((b >> i) & 1) == 1 {
                let val = 1usize << i;
                stack.push(val);
                target += val;
            }
        }
        println!("{}", stack.len());
        println!("{}", stack.iter().map(|v| v.to_string()).collect::<Vec<_>>().join(" "));
    }
}
0