結果

問題 No.714 回転寿司屋のシミュレート
ユーザー taotao54321taotao54321
提出日時 2018-09-27 23:23:57
言語 Rust
(1.77.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 3,076 bytes
コンパイル時間 1,288 ms
コンパイル使用メモリ 181,944 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 09:14:09
合計ジャッジ時間 2,310 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 6 ms
6,940 KB
testcase_07 AC 8 ms
6,944 KB
testcase_08 AC 13 ms
6,940 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 5 ms
6,944 KB
testcase_12 AC 5 ms
6,940 KB
testcase_13 AC 4 ms
6,940 KB
testcase_14 AC 5 ms
6,940 KB
testcase_15 AC 5 ms
6,940 KB
testcase_16 AC 4 ms
6,940 KB
testcase_17 AC 4 ms
6,940 KB
testcase_18 AC 4 ms
6,944 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 4 ms
6,944 KB
testcase_21 AC 4 ms
6,944 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 2 ms
6,948 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 3 ms
6,944 KB
testcase_29 AC 3 ms
6,944 KB
testcase_30 AC 1 ms
6,944 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 1 ms
6,940 KB
testcase_33 AC 1 ms
6,944 KB
testcase_34 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(non_snake_case)]

use std::collections::{ HashMap };

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut tokens = $s.split_whitespace();
        input_inner! { tokens, $($r)* }
    };

    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut res = String::new();
            ::std::io::stdin().read_to_string(&mut res).unwrap();
            res
        };
        let mut tokens = s.split_whitespace();
        input_inner! { tokens, $($r)* }
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($tokens:expr)  => {};
    ($tokens:expr,) => {};

    ($tokens:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($tokens, $t);
        input_inner! { $tokens $($r)* }
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($tokens:expr, ( $($t:tt),* )) => {
        $(read_value!($tokens, $t)),*
    };

    ($tokens:expr, [ $t:tt; $len:expr ]) => {
        (0..$len).map(|_| read_value!($tokens, $t)).collect::<Vec<_>>()
    };

    ($tokens:expr, chars) => {
        read_value!($tokens, String).chars().collect::<Vec<_>>()
    };

    ($tokens:expr, usize1) => {
        read_value!($tokens, usize) - 1
    };

    ($tokens:expr, $t:ty) => {
        $tokens.next().unwrap().parse::<$t>().expect("parse error")
    };
}

fn main() {
    const N_SEAT: usize = 20;
    type Wish = HashMap<String,u32>;

    use std::io::prelude::*;
    let stdin = ::std::io::stdin();
    let mut stdin = stdin.lock();

    let mut line = String::new();
    stdin.read_line(&mut line).unwrap();
    input! { source=line, N_DATA: usize }

    let mut seats = vec![Wish::new(); N_SEAT];

    for _ in 0..N_DATA {
        let mut line = String::new();
        stdin.read_line(&mut line).unwrap();
        let s1 = line[..1].to_owned();
        let s2 = line[2..].to_owned();

        input! { source=s1, TYPE: i32 }

        match TYPE {
            0 => {
                input! {
                    source=s2,
                    N: usize1,
                    M: usize,
                    A: [String; M],
                }
                let wish = &mut seats[N];
                for a in A {
                    *wish.entry(a).or_insert(0) += 1;
                }
            },
            1 => {
                input! {
                    source=s2,
                    B: String,
                }
                let mut ans = -1i64;
                for i in 0..N_SEAT {
                    let wish = &mut seats[i];
                    let count = wish.entry(B.clone()).or_insert(0);
                    if *count > 0 {
                        *count -= 1;
                        ans = i as i64 + 1;
                        break;
                    }
                }
                println!("{}", ans);
            },
            2 => {
                input! {
                    source=s2,
                    C: usize1
                }
                seats[C] = Wish::new();
            },
            _ => { panic!(); }
        }
    }
}
0