Submission details
Task:Maalaus
Sender:madde
Submission time:2026-10-25 12:46:15 +0200
Language:Rust (2021)
Status:READY
Result:10
Feedback
subtaskverdictscore
#1ACCEPTED10
#20
#30
#40
Test results
testverdicttimesubtask
#1ACCEPTED0.00 s1, 3, 4details
#2ACCEPTED0.00 s3, 4details
#3ACCEPTED0.00 s1, 3, 4details
#4--2, 4details
#5--2, 4details
#60.03 s3, 4details
#7ACCEPTED0.02 s3, 4details
#8--4details
#9--4details
#10ACCEPTED0.00 s1, 3, 4details
#11ACCEPTED0.00 s1, 3, 4details
#12--2, 4details
#13--2, 4details
#14--4details
#15--4details
#16--4details
#17--4details

Code

use std::{convert::Infallible, io::Write, str::FromStr};

#[derive(Clone, Copy, Debug, PartialEq)]
struct Command {
    vertical: bool,
    index: u32,
    color: u32,
}

impl FromStr for Command {
    type Err = Infallible;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(match *s.split_ascii_whitespace().collect::<Box<[&str]>>() {
            ["R", row, color] => Command {
                vertical: false,
                index: row.parse::<u32>().unwrap() - 1,
                color: color.parse::<u32>().unwrap() - 1,
            },
            ["C", col, color] => Command {
                vertical: true,
                index: col.parse::<u32>().unwrap() - 1,
                color: color.parse::<u32>().unwrap() - 1,
            },
            _ => panic!(),
        })
    }
}

fn main() {
    let input = std::io::stdin().lines().next().unwrap().unwrap();
    let mut input = input.split_ascii_whitespace().map(|l| l.parse().unwrap());
    let height: u32 = input.next().unwrap();
    let width = input.next().unwrap();
    let colors = input.next().unwrap();
    let instruction_count = input.next().unwrap() as usize;
    drop(input);
    let mut color_counts = [0; 200_000];
    //stores indecies
    let mut last_vert_paints = vec![0u32; width as usize];
    let mut last_hoiz_paints = vec![0u32; height as usize];
    let mut commands: Vec<Option<Command>> = Vec::with_capacity(instruction_count);
    let mut stdout = std::io::stdout().lock();

    for command in std::io::stdin()
        .lines()
        .take(instruction_count)
        .map(|l| l.unwrap().parse::<Command>().unwrap())
    {
        let old_paint_idx = if command.vertical {
            &mut last_vert_paints[command.index as usize]
        } else {
            &mut last_hoiz_paints[command.index as usize]
        };
        let real_old_paint_idx = old_paint_idx.saturating_sub(1);

        let old_crossings =
            inspect_crossings(&commands, real_old_paint_idx, command, &mut color_counts);
        let old_color_amount = if command.vertical {
            color_counts[command.color as usize] += height;
            height - old_crossings
        } else {
            color_counts[command.color as usize] += width;
            width - old_crossings
        };
        if *old_paint_idx != 0 {
            color_counts[commands[real_old_paint_idx as usize]
                .as_ref()
                .unwrap()
                .color as usize] -= old_color_amount;
            commands[real_old_paint_idx as usize] = None;
        }
        commands.push(Some(command));
        *old_paint_idx = commands.len() as u32;
    }
    for color in color_counts.iter().take(colors as usize) {
        print!("{} ", color)
    }
    stdout.flush().unwrap();
}

fn inspect_crossings(
    commands: &[Option<Command>],
    real_old_paint_idx: u32,
    command: Command,
    color_counts: &mut [u32; 200_000],
) -> u32 {
    let commands_to_check = commands
        .iter()
        .rev()
        .take(commands.len() - real_old_paint_idx as usize)
        .flatten();

    commands_to_check
        .filter(|cmd| {
            if cmd.vertical != command.vertical {
                color_counts[cmd.color as usize] -= 1;
                true
            } else {
                false
            }
        })
        .count() as u32
}

Test details

Test 1 (public)

Subtask: 1, 3, 4

Verdict: ACCEPTED

input
3 4 4 4
R 1 1
C 3 4
R 2 2
R 1 1

correct output
4 4 0 1

user output
4 4 0 1 

Test 2 (public)

Subtask: 3, 4

Verdict: ACCEPTED

input
1000000000 1000000000 5 10
C 70724881 4
C 290904744 1
C 569311326 5
R 896293092 1
...

correct output
3999999991 1999999998 19999999...

user output
3999999991 1999999998 19999999...

Test 3

Subtask: 1, 3, 4

Verdict: ACCEPTED

input
10 10 10 10
R 10 8
C 1 2
R 10 2
R 1 4
...

correct output
0 13 0 8 7 20 0 0 10 7

user output
0 13 0 8 7 20 0 0 10 7 

Test 4

Subtask: 2, 4

Verdict:

input
1000000000 1000000000 1 200000
R 185082082 1
C 549662476 1
R 484749097 1
R 330334821 1
...

correct output
199984000629575

user output
(empty)

Test 5

Subtask: 2, 4

Verdict:

input
1000000000 1000000000 1 200000
C 354072394 1
C 221236382 1
C 63527838 1
C 538599654 1
...

correct output
126261014543986

user output
(empty)

Test 6

Subtask: 3, 4

Verdict:

input
1000000000 1000000000 2000 200...

correct output
999999400 2999997760 999999118...

user output
999999400 2999997760 999999118...

Feedback: Incorrect character on line 1 col 1251: expected "4999997617", got "705030321"

Test 7

Subtask: 3, 4

Verdict: ACCEPTED

input
1000000000 1000000000 2000 200...

correct output
999999481 0 999999445 0 0 0 0 ...

user output
999999481 0 999999445 0 0 0 0 ...

Test 8

Subtask: 4

Verdict:

input
1000000000 1000000000 200000 2...

correct output
0 0 999997829 0 1999872519 199...

user output
(empty)

Test 9

Subtask: 4

Verdict:

input
1000000000 1000000000 200000 2...

correct output
999986843 0 0 999966411 999971...

user output
(empty)

Test 10

Subtask: 1, 3, 4

Verdict: ACCEPTED

input
1 10 10 10
C 1 10
R 1 4
C 9 3
R 1 7
...

correct output
1 0 0 0 0 0 0 9 0 0

user output
1 0 0 0 0 0 0 9 0 0 

Test 11

Subtask: 1, 3, 4

Verdict: ACCEPTED

input
10 1 10 10
R 4 6
R 5 1
R 4 2
R 3 9
...

correct output
0 0 0 0 0 0 0 10 0 0

user output
0 0 0 0 0 0 0 10 0 0 

Test 12

Subtask: 2, 4

Verdict:

input
1 1000000000 1 200000
C 298761159 1
R 1 1
C 831911362 1
C 25171734 1
...

correct output
1000000000

user output
(empty)

Test 13

Subtask: 2, 4

Verdict:

input
1000000000 1 1 200000
R 68306849 1
C 1 1
C 1 1
R 485427101 1
...

correct output
1000000000

user output
(empty)

Test 14

Subtask: 4

Verdict:

input
1000000000 1000000000 100 2000...

correct output
2003899199298 2016897879262 20...

user output
(empty)

Test 15

Subtask: 4

Verdict:

input
1000000000 1000000000 100 2000...

correct output
1267960483393 1326958437362 12...

user output
(empty)

Test 16

Subtask: 4

Verdict:

input
1000000000 1000000000 10000 20...

correct output
26998778013 13999380552 239989...

user output
(empty)

Test 17

Subtask: 4

Verdict:

input
1000000000 1000000000 10000 20...

correct output
7999699356 8999760379 12999665...

user output
(empty)