結果

問題 No.1328 alligachi-problem
ユーザー fukafukatanifukafukatani
提出日時 2020-12-27 11:13:15
言語 Rust
(1.77.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 3,487 bytes
コンパイル時間 1,091 ms
コンパイル使用メモリ 188,152 KB
実行使用メモリ 11,868 KB
最終ジャッジ日時 2024-04-08 14:44:08
合計ジャッジ時間 8,330 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 0 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 1 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 1 ms
6,548 KB
testcase_09 AC 115 ms
11,864 KB
testcase_10 AC 91 ms
11,864 KB
testcase_11 AC 123 ms
11,820 KB
testcase_12 AC 114 ms
11,860 KB
testcase_13 AC 114 ms
11,864 KB
testcase_14 AC 114 ms
11,820 KB
testcase_15 AC 91 ms
11,868 KB
testcase_16 AC 115 ms
11,864 KB
testcase_17 AC 114 ms
11,860 KB
testcase_18 AC 114 ms
11,864 KB
testcase_19 AC 114 ms
11,860 KB
testcase_20 AC 115 ms
11,864 KB
testcase_21 AC 114 ms
11,860 KB
testcase_22 AC 116 ms
11,820 KB
testcase_23 AC 95 ms
11,820 KB
testcase_24 AC 95 ms
11,860 KB
testcase_25 AC 93 ms
11,820 KB
testcase_26 AC 96 ms
11,860 KB
testcase_27 AC 96 ms
11,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut balls = vec![];
    for i in 0..n {
        let v = read_vec::<String>();
        let y: usize = v[2].parse().unwrap();
        let (c, x, y) = (
            v[0].chars().next().unwrap(),
            v[1].chars().next().unwrap(),
            y,
        );
        balls.push((c, x, y, i));
    }
    let mut red_cond = vec![];
    let mut blue_cond = vec![];

    for (c, x, y, i) in balls {
        let same;
        if c == x {
            same = 1;
        } else {
            same = 0;
        }
        if x == 'R' {
            red_cond.push((y, same, i));
        } else {
            blue_cond.push((y, same, i));
        }
    }
    red_cond.sort();
    blue_cond.sort();

    let mut red_cond = red_cond.into_iter().collect::<VecDeque<_>>();
    let mut blue_cond = blue_cond.into_iter().collect::<VecDeque<_>>();

    let mut r_count = 0;
    let mut b_count = 0;
    let mut answers = vec![];
    while !red_cond.is_empty() || !blue_cond.is_empty() {
        let mut changed = false;

        let mut used = true;
        if let Some(&(_, same, _)) = red_cond.iter().next() {
            if let Some(&(y1, _, _)) = blue_cond.iter().next() {
                if y1 == b_count && same == 0 {
                    used = false;
                }
            }
        }
        if used {
            if let Some(&(y, same, idx)) = red_cond.iter().next() {
                if y == r_count {
                    red_cond.pop_front();
                    if same == 1 {
                        r_count += 1;
                    } else {
                        b_count += 1;
                    }
                    answers.push(idx);
                    changed = true;
                }
            }
        }

        let mut used = true;
        if let Some(&(_, same, _)) = blue_cond.iter().next() {
            if let Some(&(y1, _, _)) = red_cond.iter().next() {
                if y1 == r_count && same == 0 {
                    used = false;
                }
            }
        }
        if used {
            if let Some(&(y, same, idx)) = blue_cond.iter().next() {
                if y == b_count {
                    blue_cond.pop_front();
                    if same == 1 {
                        b_count += 1;
                    } else {
                        r_count += 1;
                    }
                    answers.push(idx);
                    changed = true;
                }
            }
        }

        if !changed {
            // debug!((answers, r_count, b_count));
            println!("No");
            return;
        }
    }
    debug!(answers);
    println!("Yes");
    for num in answers.iter().take(n - 1) {
        print!("{} ", num + 1);
    }
    println!("{}", answers[n - 1] + 1);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0