結果

問題 No.2658 L-R Nim
ユーザー akakimidoriakakimidori
提出日時 2024-03-01 23:02:49
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 1,964 ms / 7,000 ms
コード長 6,211 bytes
コンパイル時間 17,226 ms
コンパイル使用メモリ 403,156 KB
実行使用メモリ 327,424 KB
最終ジャッジ日時 2024-09-29 14:48:52
合計ジャッジ時間 65,638 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,816 KB
testcase_03 AC 1 ms
6,816 KB
testcase_04 AC 1 ms
6,816 KB
testcase_05 AC 188 ms
31,360 KB
testcase_06 AC 192 ms
31,104 KB
testcase_07 AC 198 ms
31,360 KB
testcase_08 AC 191 ms
31,232 KB
testcase_09 AC 192 ms
31,232 KB
testcase_10 AC 191 ms
31,232 KB
testcase_11 AC 195 ms
31,232 KB
testcase_12 AC 188 ms
31,104 KB
testcase_13 AC 189 ms
31,104 KB
testcase_14 AC 189 ms
31,232 KB
testcase_15 AC 190 ms
31,104 KB
testcase_16 AC 194 ms
31,104 KB
testcase_17 AC 186 ms
31,360 KB
testcase_18 AC 191 ms
31,232 KB
testcase_19 AC 195 ms
31,488 KB
testcase_20 AC 201 ms
31,744 KB
testcase_21 AC 195 ms
31,232 KB
testcase_22 AC 190 ms
31,488 KB
testcase_23 AC 190 ms
31,232 KB
testcase_24 AC 196 ms
31,104 KB
testcase_25 AC 1,425 ms
147,840 KB
testcase_26 AC 1,413 ms
148,096 KB
testcase_27 AC 1,437 ms
147,712 KB
testcase_28 AC 1,441 ms
147,712 KB
testcase_29 AC 1,449 ms
147,456 KB
testcase_30 AC 1,446 ms
147,200 KB
testcase_31 AC 1,456 ms
147,456 KB
testcase_32 AC 1,442 ms
147,584 KB
testcase_33 AC 781 ms
82,432 KB
testcase_34 AC 1,359 ms
130,688 KB
testcase_35 AC 1,824 ms
302,336 KB
testcase_36 AC 1,415 ms
147,968 KB
testcase_37 AC 1,964 ms
327,424 KB
testcase_38 AC 1,452 ms
147,328 KB
testcase_39 AC 1,443 ms
147,584 KB
testcase_40 AC 1,438 ms
148,096 KB
testcase_41 AC 1,447 ms
147,840 KB
testcase_42 AC 1,447 ms
147,712 KB
testcase_43 AC 1,432 ms
147,712 KB
testcase_44 AC 1,441 ms
147,200 KB
testcase_45 AC 1,450 ms
147,968 KB
testcase_46 AC 1,461 ms
147,584 KB
testcase_47 AC 1,412 ms
147,584 KB
testcase_48 AC 1,426 ms
147,584 KB
testcase_49 AC 1,449 ms
147,968 KB
testcase_50 AC 1,431 ms
147,584 KB
testcase_51 AC 1,463 ms
148,224 KB
testcase_52 AC 1,431 ms
147,840 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::io::Write`
 --> src/main.rs:4:5
  |
4 | use std::io::Write;
  |     ^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: type alias `Set` is never used
 --> src/main.rs:8:6
  |
8 | type Set<T> = BTreeSet<T>;
  |      ^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: type alias `Deque` is never used
 --> src/main.rs:9:6
  |
9 | type Deque<T> = VecDeque<T>;
  |      ^^^^^

ソースコード

diff #

// 累積xorが一致しないようにしたい
// 

use std::io::Write;
use std::collections::*;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

fn main() {
    input! {
        n: usize,
        k: usize,
        a: [usize; n],
    }
    let mut map = Map::new();
    for (i, &a) in a.iter().enumerate() {
        let mut x = vec![0];
        for i in 1..=k {
            if i < a {
                x.push(a ^ (a - i));
            }
            x.push(a ^ (a + i));
        }
        x.sort();
        x.dedup();
        for x in x {
            map.entry(x).or_insert(vec![]).push(i);
        }
    }
    let mut ban = Map::new();
    let mut last = vec![None; 1 << 21];
    last[0] = Some(n);
    let mut xor = 0;
    let mut r = n;
    let mut l = 0;
    for (i, a) in a.iter().enumerate().rev() {
        xor ^= a;
        for &x in map.keys() {
            if let Some(y) = last[xor ^ x] {
                ban.entry(x).or_insert(vec![]).push((i, y));
            }
        }
        if let Some(y) = last[xor] {
            l = l.max(i);
            r = r.min(y);
        }
        last[xor] = Some(i);
    }
    if l >= r {
        println!("No");
        return;
    }
    for (x, pos) in map {
        let po = ban.entry(x).or_insert(vec![]);
        po.sort_by_key(|p| (p.0, !p.1));
        po.dedup_by(|a, b| b.1 >= a.0 && {
            b.1 = b.1.max(a.1);
            true
        });
        for &pos in pos.iter() {
            if !(l <= pos && pos < r) {
                continue;
            }
            let u = po.upper_bound_by_key(&pos, |p| p.0);
            if u == 0 || po[u - 1].1 <= pos {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------
// ---------- begin super slice ----------
pub trait SuperSlice {
    type Item;
    fn lower_bound(&self, key: &Self::Item) -> usize
    where
        Self::Item: Ord;
    fn lower_bound_by<F>(&self, f: F) -> usize
    where
        F: FnMut(&Self::Item) -> std::cmp::Ordering;
    fn lower_bound_by_key<K, F>(&self, key: &K, f: F) -> usize
    where
        K: Ord,
        F: FnMut(&Self::Item) -> K;
    fn upper_bound(&self, key: &Self::Item) -> usize
    where
        Self::Item: Ord;
    fn upper_bound_by<F>(&self, f: F) -> usize
    where
        F: FnMut(&Self::Item) -> std::cmp::Ordering;
    fn upper_bound_by_key<K, F>(&self, key: &K, f: F) -> usize
    where
        K: Ord,
        F: FnMut(&Self::Item) -> K;
    fn next_permutation(&mut self) -> bool
    where
        Self::Item: Ord;
    fn next_permutation_by<F>(&mut self, f: F) -> bool
    where
        F: FnMut(&Self::Item, &Self::Item) -> std::cmp::Ordering;
    fn prev_permutation(&mut self) -> bool
    where
        Self::Item: Ord;
}

impl<T> SuperSlice for [T] {
    type Item = T;
    fn lower_bound(&self, key: &Self::Item) -> usize
    where
        T: Ord,
    {
        self.lower_bound_by(|p| p.cmp(key))
    }
    fn lower_bound_by<F>(&self, mut f: F) -> usize
    where
        F: FnMut(&Self::Item) -> std::cmp::Ordering,
    {
        self.binary_search_by(|p| f(p).then(std::cmp::Ordering::Greater))
            .unwrap_err()
    }
    fn lower_bound_by_key<K, F>(&self, key: &K, mut f: F) -> usize
    where
        K: Ord,
        F: FnMut(&Self::Item) -> K,
    {
        self.lower_bound_by(|p| f(p).cmp(key))
    }
    fn upper_bound(&self, key: &Self::Item) -> usize
    where
        T: Ord,
    {
        self.upper_bound_by(|p| p.cmp(key))
    }
    fn upper_bound_by<F>(&self, mut f: F) -> usize
    where
        F: FnMut(&Self::Item) -> std::cmp::Ordering,
    {
        self.binary_search_by(|p| f(p).then(std::cmp::Ordering::Less))
            .unwrap_err()
    }
    fn upper_bound_by_key<K, F>(&self, key: &K, mut f: F) -> usize
    where
        K: Ord,
        F: FnMut(&Self::Item) -> K,
    {
        self.upper_bound_by(|p| f(p).cmp(key))
    }
    fn next_permutation(&mut self) -> bool
    where
        T: Ord,
    {
        self.next_permutation_by(|a, b| a.cmp(b))
    }
    fn next_permutation_by<F>(&mut self, mut f: F) -> bool
    where
        F: FnMut(&Self::Item, &Self::Item) -> std::cmp::Ordering,
    {
        use std::cmp::Ordering::*;
        if let Some(x) = self.windows(2).rposition(|a| f(&a[0], &a[1]) == Less) {
            let y = self.iter().rposition(|b| f(&self[x], b) == Less).unwrap();
            self.swap(x, y);
            self[(x + 1)..].reverse();
            true
        } else {
            self.reverse();
            false
        }
    }
    fn prev_permutation(&mut self) -> bool
    where
        T: Ord,
    {
        self.next_permutation_by(|a, b| a.cmp(b).reverse())
    }
}
// ---------- end super slice ----------

0