Submission #51605958


Source Code Expand

// -*- coding:utf-8-unix -*-
/*
このコード、と~おれ!
  ∧_∧ 
(。・ω・。)つ━☆・*。
⊂    ノ       ・゜+.
 しーJ       °。+ *´¨)
                  .· ´¸.·*´¨) ¸.·*¨)
                                      (¸.·´ (¸.·'* ☆
*/

use std::cmp::Reverse;
#[allow(unused_imports)]
use ac_library::*;
use itertools::Itertools;
use proconio::input;
use proconio::marker::Chars;
use std::collections::{BinaryHeap, BTreeMap, VecDeque};


static INF: usize = 1e18 as usize;

trait ChLibs<T: std::cmp::Ord> {
    fn chmin(&mut self, elm: T) -> bool;
    fn chmax(&mut self, elm: T) -> bool;
}

impl<T: std::cmp::Ord> ChLibs<T> for T {
    fn chmin(&mut self, elm: T) -> bool {
        return
            if *self > elm { *self = elm; true }
            else { false }
    }

    fn chmax(&mut self, elm: T) -> bool {
        return
            if *self < elm { *self = elm; true }
            else { false }
    }
}

trait Vector<T> {
    fn insertion_sort(&mut self, elem: T);
    fn print_continuous(&self);
    fn print_space_separate(&self);
    fn print_linebreak(&self);
}

impl<T: std::cmp::Ord  + std::fmt::Display> Vector<T> for Vec<T> {
    fn insertion_sort(&mut self, elem: T) { let idx = self.binary_search(&elem).unwrap_or_else(|x| x); self.insert(idx, elem); }
    fn print_continuous(&self) { for i in 0..self.len() { print!("{}", self[i]); } println!() }
    fn print_space_separate(&self) { for i in 0..self.len() { print!("{}", self[i]); if i != self.len()-1 { print!(" ") } } println!() }
    fn print_linebreak(&self) { for i in 0..self.len() { println!("{}", self[i]); } }
}

fn solve(){
    input! {
        h: usize,
        w: usize,
        m: usize,
        queries: [(u64, u64, u64); m]
    }

    // h => t = 1
    let mut h_last_query = vec![(0u64, 0u64, 1u64); h];
    let mut w_last_query = vec![(0u64, 0u64, 2u64); w];

    for (idx, &(t, a, x)) in queries.iter().enumerate() {
        match t {
            1 =>{
                h_last_query[(a-1) as usize] = ((idx + 1) as u64, x, 1);
            },
            2 => {
                w_last_query[(a-1) as usize] = ((idx + 1) as u64, x, 2);
            },
            _ => unreachable!()
        }
    }

    let mut last = vec![];
    for x in &h_last_query {
        last.push(*x);
    }

    for x in &w_last_query {
        last.push(*x)
    }

    last.sort_by_key(|x| Reverse(x.0));
    let mut ans = BTreeMap::new();

    let mut h_sum = 0;
    let mut w_sum = 0;

    for &(_, color, r) in &last {
        if r == 1 {
            h_sum += 1;

            if w as u64 != w_sum {
                *ans.entry(color).or_insert(0u64) += w as u64 - w_sum;
            }
        }else{
            w_sum += 1;

            if h as u64 != h_sum {
                *ans.entry(color).or_insert(0u64) += h as u64 - h_sum;
            }
        }
    }

    println!("{}", ans.len());
    for (k, v) in &ans {
        println!("{} {}", *k, *v);
    }

}

fn main() {
    // input! { i: usize }
    let mut i = 1;
    while i != 0 { solve(); i -= 1; }
}



Submission Info

Submission Time
Task E - Paint
User ardRiriy
Language Rust (rustc 1.70.0)
Score 450
Code Size 3078 Byte
Status AC
Exec Time 169 ms
Memory 32668 KiB

Compile Error

warning: unused import: `itertools::Itertools`
  --> src/main.rs:15:5
   |
15 | use itertools::Itertools;
   |     ^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: unused import: `proconio::marker::Chars`
  --> src/main.rs:17:5
   |
17 | use proconio::marker::Chars;
   |     ^^^^^^^^^^^^^^^^^^^^^^^

warning: unused imports: `BinaryHeap`, `VecDeque`
  --> src/main.rs:18:24
   |
18 | use std::collections::{BinaryHeap, BTreeMap, VecDeque};
   |                        ^^^^^^^^^^            ^^^^^^^^

warning: static `INF` is never used
  --> src/main.rs:21:8
   |
21 | static INF: usize = 1e18 as usize;
   |        ^^^
   |
   = note: `#[warn(dead_code)]` on by default

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 43
Set Name Test Cases
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt, testcase38.txt, testcase39.txt
Case Name Status Exec Time Memory
sample00.txt AC 1 ms 2012 KiB
sample01.txt AC 1 ms 2012 KiB
sample02.txt AC 0 ms 2000 KiB
testcase00.txt AC 129 ms 24092 KiB
testcase01.txt AC 128 ms 24924 KiB
testcase02.txt AC 128 ms 24684 KiB
testcase03.txt AC 138 ms 26428 KiB
testcase04.txt AC 125 ms 23760 KiB
testcase05.txt AC 135 ms 25656 KiB
testcase06.txt AC 127 ms 23808 KiB
testcase07.txt AC 132 ms 25568 KiB
testcase08.txt AC 128 ms 24384 KiB
testcase09.txt AC 129 ms 24540 KiB
testcase10.txt AC 128 ms 24816 KiB
testcase11.txt AC 136 ms 26108 KiB
testcase12.txt AC 123 ms 16836 KiB
testcase13.txt AC 128 ms 17712 KiB
testcase14.txt AC 122 ms 16916 KiB
testcase15.txt AC 131 ms 17868 KiB
testcase16.txt AC 116 ms 16440 KiB
testcase17.txt AC 126 ms 17712 KiB
testcase18.txt AC 110 ms 31296 KiB
testcase19.txt AC 117 ms 31632 KiB
testcase20.txt AC 41 ms 10600 KiB
testcase21.txt AC 46 ms 10876 KiB
testcase22.txt AC 44 ms 10860 KiB
testcase23.txt AC 37 ms 10568 KiB
testcase24.txt AC 40 ms 10988 KiB
testcase25.txt AC 96 ms 15504 KiB
testcase26.txt AC 88 ms 14932 KiB
testcase27.txt AC 69 ms 12588 KiB
testcase28.txt AC 81 ms 13996 KiB
testcase29.txt AC 98 ms 15876 KiB
testcase30.txt AC 166 ms 31580 KiB
testcase31.txt AC 165 ms 31852 KiB
testcase32.txt AC 162 ms 31484 KiB
testcase33.txt AC 167 ms 31096 KiB
testcase34.txt AC 167 ms 31988 KiB
testcase35.txt AC 169 ms 32336 KiB
testcase36.txt AC 169 ms 32312 KiB
testcase37.txt AC 169 ms 32668 KiB
testcase38.txt AC 168 ms 32644 KiB
testcase39.txt AC 169 ms 32228 KiB