結果

問題 No.1377 Half xor Half
ユーザー koba-e964koba-e964
提出日時 2021-11-29 22:20:19
言語 Rust
(1.72.1)
結果
WA  
実行時間 -
コード長 3,108 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 154,460 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-15 09:51:29
合計ジャッジ時間 7,030 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
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 AC 1 ms
4,384 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
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 -
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 1 ms
4,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 2 ms
4,376 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 1 ms
4,376 KB
testcase_46 WA -
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
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),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); }
impl<T: PartialOrd> Change for T {
    fn chmax(&mut self, x: T) { if *self < x { *self = x; } }
    fn chmin(&mut self, x: T) { if *self > x { *self = x; } }
}

// https://yukicoder.me/problems/no/1377 (3)
// x=i と x=i+1 をこの順番で行うと (a[i], a[i + n]) が (0, 0) -> (0, 0), (0, 1) -> (1, 0), (1, 0) -> (1, 1), (1, 1) -> (0, 1) となる。逆順だと (0, 0) -> (0, 0), (0, 1) -> (1, 1), (1, 0) -> (0, 1), (1, 1) -> (1, 0) となる。これで全ての遷移が尽くされたので、(0, 0) とそれ以外の間の遷移がなければ 2N 回以内に可能。
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,
        s: chars,
        t: chars,
    }
    let tbl = [
        [0, -1, -1, -1],
        [-1, 0, 1, 2],
        [-1, 2, 0, 1],
        [-1, 1, 2, 0],
    ];
    let get = |s: &[char], x: usize| -> usize {
        let a = s[x] as u8 - b'0';
        let b = s[n + x] as u8 - b'0';
        (a * 2 + b) as usize
    };
    let mut ans = vec![];
    for i in 0..n {
        let a = get(&s, i);
        let b = get(&t, i);
        let k = tbl[a][b];
        if k < 0 {
            puts!("-1\n");
            return;
        }
        if k > 0 {
            if k == 1 {
                ans.push(i);
                ans.push(n + i);
            } else {
                ans.push(n + i);
                ans.push(i);
            }
        }
    }
    puts!("{}\n", ans.len());
    for a in ans {
        puts!("{}\n", a);
    }
}
0