結果

問題 No.2844 Birthday Party Decoration
ユーザー naut3naut3
提出日時 2024-08-23 23:06:36
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,506 bytes
コンパイル時間 13,412 ms
コンパイル使用メモリ 402,600 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-08-23 23:06:51
合計ジャッジ時間 14,497 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unnecessary parentheses around assigned value
  --> src/main.rs:34:21
   |
34 |             let k = (X.next_power_of_two() >> 1);
   |                     ^                          ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
34 -             let k = (X.next_power_of_two() >> 1);
34 +             let k = X.next_power_of_two() >> 1;
   |

ソースコード

diff #

#![allow(non_snake_case, unused_must_use, unused_imports)]
use std::io::{self, prelude::*};

fn main() {
    let (stdin, stdout) = (io::read_to_string(io::stdin()).unwrap(), io::stdout());
    let (mut stdin, mut buffer) = (stdin.split_whitespace(), io::BufWriter::new(stdout.lock()));
    for _ in 0..stdin.next().unwrap().parse::<usize>().unwrap() {
        solve(&mut stdin, &mut buffer);
    }
}

fn solve(stdin: &mut std::str::SplitWhitespace, buffer: &mut io::BufWriter<io::StdoutLock>) {
    macro_rules! input {
        ($t: ty) => {
            stdin.next().unwrap().parse::<$t>().unwrap()
        };
        ($t: ty, $n: expr) => {
            (0..$n).map(|_| input!($t)).collect::<Vec<_>>()
        };
    }

    let N = input!(usize);
    let X = input!(u64);
    let C = input!(u64, N);

    let mut ans = u64::MAX;

    // 左側
    let mut left = X;
    let mut isok = true;

    for &c in C.iter() {
        if (X >> c) & 1 != 1 {
            let k = (X.next_power_of_two() >> 1);

            if k > 0 {
                left = std::cmp::min(left, k - 1);
            } else {
                isok = false;
            }
        }
    }

    if isok {
        ans = std::cmp::min(ans, (X - left) * 2);
    }

    // 右側
    let mut right = X;

    for c in C {
        if (X >> c) & 1 != 1 {
            let k = ((X >> c) << c) + (1 << c);

            right = std::cmp::max(right, k);
        }
    }

    ans = std::cmp::min(ans, (right - X) * 2);

    writeln!(buffer, "{}", ans);
}
0