提出 #53921848


ソースコード 拡げる

use proconio::input;

trait Bound<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: PartialOrd> Bound<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let (mut low, mut high) = (0, self.len());
        while low + 1 < high {
            let mid = (low + high) / 2;
            if self[mid] < *x {
                low = mid;
            } else {
                high = mid;
            }
        }
        if self[low] < *x {
            low + 1
        } else {
            low
        }
    }

    fn upper_bound(&self, x: &T) -> usize {
        let (mut low, mut high) = (0, self.len());
        while low + 1 < high {
            let mid = (low + high) / 2;
            if self[mid] <= *x {
                low = mid;
            } else {
                high = mid;
            }
        }
        if self[low] <= *x {
            low + 1
        } else {
            low
        }
    }
}

fn main() {
    input! {n:usize,cards:[(i32,i32);n]}
    let mut is_takahashi_win = vec![false; 1 << n];

    for i in 0..(1 << n) {
        let mut f = false;
        for j in 0..n {
            for k in (j + 1)..n {
                if ((i >> j & 1) == 1) && ((i >> k & 1) == 1) { // i,jに対応したカードが場にあるか判定
                    let mask = !((1 << j) | (1 << k)); // i,j以外が1のマスクを生成
                    if (cards[j].0 == cards[k].0 || cards[j].1 == cards[k].1)
                        && !is_takahashi_win[i & mask] // 場のカードにi,jを取り除くマスクをかける == 遷移後の状態を取得する
                    {
                        f = true
                    }
                }
            }
        }
        is_takahashi_win[i] = f;
    }

    println!(
        "{}",
        if *is_takahashi_win.last().unwrap() {
            "Takahashi"
        } else {
            "Aoki"
        }
    )
}

提出情報

提出日時
問題 E - Remove Pairs
ユーザ tsu7magu6
言語 Rust (rustc 1.70.0)
得点 475
コード長 2007 Byte
結果 AC
実行時間 83 ms
メモリ 2168 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 475 / 475
結果
AC × 2
AC × 30
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 02_hand_00.txt, 02_hand_01.txt, 02_hand_02.txt, 02_hand_03.txt, 02_hand_04.txt, 02_hand_05.txt, 02_hand_06.txt, 02_hand_07.txt, 02_hand_08.txt, 02_hand_09.txt, 02_hand_10.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 1856 KiB
00_sample_01.txt AC 1 ms 1932 KiB
01_random_00.txt AC 29 ms 2012 KiB
01_random_01.txt AC 4 ms 2096 KiB
01_random_02.txt AC 1 ms 1832 KiB
01_random_03.txt AC 1 ms 1856 KiB
01_random_04.txt AC 1 ms 1924 KiB
01_random_05.txt AC 4 ms 1924 KiB
01_random_06.txt AC 1 ms 2024 KiB
01_random_07.txt AC 83 ms 2024 KiB
01_random_08.txt AC 77 ms 1964 KiB
01_random_09.txt AC 1 ms 1872 KiB
01_random_10.txt AC 39 ms 2020 KiB
01_random_11.txt AC 1 ms 2008 KiB
01_random_12.txt AC 2 ms 1932 KiB
01_random_13.txt AC 1 ms 1924 KiB
01_random_14.txt AC 4 ms 1864 KiB
01_random_15.txt AC 1 ms 1752 KiB
01_random_16.txt AC 9 ms 1888 KiB
02_hand_00.txt AC 67 ms 2008 KiB
02_hand_01.txt AC 65 ms 2068 KiB
02_hand_02.txt AC 76 ms 2108 KiB
02_hand_03.txt AC 76 ms 2168 KiB
02_hand_04.txt AC 78 ms 2036 KiB
02_hand_05.txt AC 76 ms 2040 KiB
02_hand_06.txt AC 78 ms 2072 KiB
02_hand_07.txt AC 74 ms 2036 KiB
02_hand_08.txt AC 80 ms 2012 KiB
02_hand_09.txt AC 80 ms 2008 KiB
02_hand_10.txt AC 75 ms 2044 KiB