結果

問題 No.945 YKC饅頭
ユーザー phsplsphspls
提出日時 2020-01-22 22:44:01
言語 Rust
(1.77.0)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 2,949 bytes
コンパイル時間 8,352 ms
コンパイル使用メモリ 163,368 KB
実行使用メモリ 51,080 KB
最終ジャッジ日時 2023-09-23 03:45:00
合計ジャッジ時間 19,469 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 13 ms
6,500 KB
testcase_32 AC 18 ms
11,888 KB
testcase_33 AC 61 ms
21,124 KB
testcase_34 AC 98 ms
26,320 KB
testcase_35 AC 223 ms
46,604 KB
testcase_36 AC 102 ms
29,588 KB
testcase_37 AC 101 ms
29,320 KB
testcase_38 AC 95 ms
26,844 KB
testcase_39 AC 35 ms
13,708 KB
testcase_40 AC 40 ms
17,424 KB
testcase_41 AC 20 ms
10,860 KB
testcase_42 AC 158 ms
37,516 KB
testcase_43 AC 91 ms
27,932 KB
testcase_44 AC 157 ms
37,780 KB
testcase_45 AC 167 ms
37,472 KB
testcase_46 AC 11 ms
7,464 KB
testcase_47 AC 109 ms
27,252 KB
testcase_48 AC 19 ms
6,992 KB
testcase_49 AC 56 ms
18,252 KB
testcase_50 AC 212 ms
39,508 KB
testcase_51 AC 259 ms
50,992 KB
testcase_52 AC 274 ms
50,956 KB
testcase_53 AC 263 ms
51,000 KB
testcase_54 AC 265 ms
51,080 KB
testcase_55 AC 266 ms
50,980 KB
testcase_56 AC 22 ms
16,564 KB
testcase_57 AC 14 ms
12,512 KB
testcase_58 AC 165 ms
41,140 KB
testcase_59 AC 190 ms
45,464 KB
testcase_60 AC 79 ms
26,304 KB
testcase_61 AC 168 ms
43,848 KB
testcase_62 AC 167 ms
41,408 KB
testcase_63 AC 14 ms
11,992 KB
testcase_64 AC 92 ms
29,008 KB
testcase_65 AC 77 ms
25,124 KB
testcase_66 AC 66 ms
24,508 KB
testcase_67 AC 122 ms
34,000 KB
testcase_68 AC 84 ms
28,480 KB
testcase_69 AC 34 ms
17,296 KB
testcase_70 AC 39 ms
18,904 KB
testcase_71 AC 40 ms
18,944 KB
testcase_72 AC 99 ms
31,808 KB
testcase_73 AC 179 ms
44,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;
use std::collections::{HashMap, BinaryHeap};

fn main() {
    const MIN_VAL: isize = -10_000_000;

    let mut all_data = String::new();
    std::io::stdin().read_to_string(&mut all_data).ok();
    let all_data: Vec<&str> = all_data.trim().split('\n').map(|s| s.trim()).collect();
    let nm: Vec<isize> = all_data.iter().next().unwrap().split_whitespace().map(|i| i.parse::<isize>().unwrap()).collect();
    let n: isize = nm[0];
    let m: isize = nm[1];
    let mut idx2kmc: HashMap<usize, String> = HashMap::new();
    let mut starts: BinaryHeap<isize> = BinaryHeap::new();
    let mut ends: BinaryHeap<isize> = BinaryHeap::new();
    let mut mapping: Vec<Vec<isize>> = vec![vec![]; (n as usize)+2];
    all_data.iter().enumerate().skip(1).take(m as usize).for_each(|pair| {
        let mark_val = pair.0 as isize;
        let values: Vec<&str> = (pair.1).split_whitespace().collect();
        let start: usize = values[0].parse::<usize>().unwrap();
        let end: usize = values[1].parse::<usize>().unwrap();
        let keyword: String = values[2].to_string();
        idx2kmc.insert(mark_val as usize, keyword);
        mapping[start].push(mark_val);
        mapping[end+1].push(-mark_val);
    });

    let mut result_map: Vec<Option<String>> = vec![None; n as usize];
    let mut current_val: isize = MIN_VAL;
    mapping.iter().skip(1).take(n as usize).enumerate().for_each(|pair| {
        let start_ends = pair.1;
        if !start_ends.is_empty() {
            start_ends.iter().for_each(|se| {
                if se > &0isize {
                    starts.push(-se);
                } else {
                    ends.push(*se);
                }
            });
        }
        if !ends.is_empty() {
            if ends.peek().unwrap() == &current_val {
                current_val = MIN_VAL;
                ends.pop();
            }
        }
        while !starts.is_empty() && !ends.is_empty() {
            if starts.peek().unwrap() != ends.peek().unwrap() {
                break;
            } else {
                starts.pop();
                ends.pop();
            }
        }
        if !starts.is_empty() {
            if starts.peek().unwrap() > &current_val {
                if current_val > MIN_VAL {
                    starts.push(current_val);
                }
                current_val = starts.pop().unwrap();
            }
        }
        let v = (-current_val) as usize;
        result_map[pair.0] = idx2kmc.get(&v).map(|i| i.to_string());
    });
    let mut y = 0;
    let mut k = 0;
    let mut c = 0;
    result_map.iter().for_each(|r| {
        match r {
            Some(x) => {
                match x.as_str() {
                    "Y" => { y += 1; },
                    "K" => { k += 1; },
                    "C" => { c += 1; },
                    _ => { },
                }
            },
            None => { },
        }
    });
    println!("{} {} {}", y, k, c);
}
0