結果

問題 No.1896 Arrays and XOR Procedure 2
ユーザー koba-e964koba-e964
提出日時 2023-06-12 11:27:01
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,538 bytes
コンパイル時間 1,238 ms
コンパイル使用メモリ 154,924 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-02 07:24:35
合計ジャッジ時間 8,443 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::cmp::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

// https://yukicoder.me/problems/no/1896 (3)
// A, B の中で一番高いビットを h とする。A の中に h が立っている数がなければ、B の数から作る。(高々 1 回)
// その後、B の全ての数で h が立っているようにする。(高々 N 回)
// その後、A の全ての数で h が立っていないようにする。(高々 N 回)
fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
    input! {
        n: usize,
        a: [u32; n],
        b: [u32; n],
    }
    let mut a = a;
    let mut b = b;
    let mut ma = 0;
    for i in 0..n {
        ma = max(ma, max(a[i], b[i]));
    }
    let mut h = 1;
    while h <= ma { h *= 2; }
    h /= 2;
    let mut ops = vec![];
    let mut idx = n;
    for i in 0..n {
        if (a[i] & h) != 0 {
            idx = i;
            break;
        }
    }
    if idx == n {
        for i in 0..n {
            if (b[i] & h) != 0 {
                idx = i;
                break;
            }
        }
        a[0] ^= b[idx];
        ops.push((1, 0, idx));
        idx = 0;
    }
    for i in 0..n {
        if (b[i] & h) == 0 {
            b[i] ^= a[idx];
            ops.push((2, idx, i));
        }
    }
    for i in 0..n {
        if (a[i] & h) == 0 {
            a[i] ^= b[0];
            ops.push((1, i, 0));
        }
    }
    puts!("{}\n", ops.len());
    for (a, b, c) in ops {
        puts!("{} {} {}\n", a, b + 1, c + 1);
    }
}
0