結果

問題 No.2343 (l+r)/2
ユーザー koba-e964koba-e964
提出日時 2023-06-13 01:54:49
言語 Rust
(1.77.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 2,394 bytes
コンパイル時間 6,930 ms
コンパイル使用メモリ 154,788 KB
実行使用メモリ 12,876 KB
最終ジャッジ日時 2023-09-02 18:24:36
合計ジャッジ時間 4,141 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 53 ms
12,876 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 20 ms
4,368 KB
testcase_04 AC 7 ms
4,368 KB
testcase_05 AC 3 ms
4,368 KB
testcase_06 AC 3 ms
4,368 KB
testcase_07 AC 8 ms
4,372 KB
testcase_08 AC 11 ms
4,368 KB
testcase_09 AC 8 ms
4,372 KB
testcase_10 AC 3 ms
4,368 KB
testcase_11 AC 9 ms
4,372 KB
testcase_12 AC 7 ms
4,368 KB
testcase_13 AC 5 ms
4,368 KB
testcase_14 AC 11 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn f(mut a: Vec<i32>) -> bool {
    let mut s = [0; 2];
    for i in 0..a.len() {
        s[a[i] as usize] += 1;
    }
    a.dedup();
    let m = a.len();
    if m % 2 == 0 { return true; }
    if m >= 9 { return true; }
    if a[0] == 0 && s[1] == m / 2 {
        return false;
    }
    if a[0] == 1 && s[0] == m / 2 {
        return false;
    }
    true
}

// https://yukicoder.me/problems/no/2343 (3.5)
// 0 と 1 が同数であれば簡単。そうでないとき、一般性を失わず 0 が多いとして良い。
// 0+(10+)* にマッチしない文字列であれば 0 を 1 と同数にまで減らすことができるので可能。
// マッチする文字列の場合はおそらく不可能と思い提出したら WA。
// -> 010101010 (len = 9) の場合、0101 を 5/8 にし、 01 を 1/2、 010 を 3/8 にして
// 01010 で 3/8 を作れば最終的に 1/2 にできる。よって長さが 9 以上で 0+(10+)* にマッチする場合も可能。
// これで提出したら AC だった。
fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
    input!(a: [[i32]]);
    for a in a {
        puts!("{}\n", if f(a) { "Yes" } else { "No" });
    }
}
0