結果

問題 No.862 XORでX
ユーザー koba-e964koba-e964
提出日時 2021-10-05 22:48:13
言語 Rust
(1.77.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,715 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 142,092 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 08:34:50
合計ジャッジ時間 4,884 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 14 ms
4,380 KB
testcase_09 AC 14 ms
4,376 KB
testcase_10 AC 14 ms
4,376 KB
testcase_11 AC 14 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 93 ms
4,376 KB
testcase_17 AC 94 ms
4,376 KB
testcase_18 AC 93 ms
4,376 KB
testcase_19 AC 94 ms
4,376 KB
testcase_20 AC 126 ms
4,380 KB
testcase_21 AC 129 ms
4,380 KB
testcase_22 AC 126 ms
4,376 KB
testcase_23 AC 127 ms
4,380 KB
testcase_24 AC 126 ms
4,380 KB
testcase_25 AC 125 ms
4,380 KB
testcase_26 AC 126 ms
4,376 KB
testcase_27 AC 126 ms
4,376 KB
testcase_28 AC 126 ms
4,376 KB
testcase_29 AC 127 ms
4,376 KB
testcase_30 AC 127 ms
4,376 KB
testcase_31 AC 127 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
    let n: usize = get();
    let x: usize = get();
    let mut ans = vec![];
    if x == 1 {
        if n % 4 == 1 {
            ans.extend(1..n + 1);
        } else if n % 4 == 2 {
            ans.extend(2..n + 2);
        } else if n % 4 == 3 {
            ans.extend(&[3, 5, 7]);
            ans.extend(8..n + 5);
        } else {
            ans.extend(&[1, 3, 4, 7]);
            ans.extend(8..n + 4);
        }
    } else {
        if n % 2 == 1 {
            let y = x ^ ((n / 2) & 1);
            ans.push(y);
            for i in 1..n / 2 + 1 {
                let tmp = (y / 2 - 1 + i) % 50002;
                ans.push(2 * tmp + 2);
                ans.push(2 * tmp + 3);
            }
        } else {
            let y = x ^ ((n / 2) & 1);
            ans.push(1);
            ans.push(y);
            for i in 1..n / 2 {
                let tmp = (y / 2 - 1 + i) % 50002;
                ans.push(2 * tmp + 2);
                ans.push(2 * tmp + 3);
            }
        }
    }
    for i in 0..n {
        println!("{}", ans[i]);
    }
}
0