CSES - Datatähti 2023 alku - Results
Submission details
Task:Ruudukko
Sender:EmuBird
Submission time:2022-11-06 20:47:25 +0200
Language:Rust
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.00 s1, 2, 3details
#20.00 s1, 2, 3details
#30.00 s1, 2, 3details
#40.01 s2, 3details
#50.02 s2, 3details
#60.02 s2, 3details
#70.00 s3details
#8--3details
#9--3details

Compiler report

warning: unused variable: `last_value`
  --> input/code.rs:44:9
   |
44 |     let last_value = values_sorted.last().unwrap();
   |         ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_last_value`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

Code

use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::io;

const MOD: u32 = (10_i32.pow(9) + 7) as u32;

fn main() {
    let dimension = {
        let mut input: String = String::new();
        io::stdin().read_line(&mut input).unwrap();
        input.strip_suffix("\n").unwrap().parse::<u16>().unwrap()
    };

    let mut rows: Vec<Vec<Cell>> = Vec::with_capacity(dimension as usize);
    let mut coordinates_by_value: HashMap<u32, Vec<(u16, u16)>> = HashMap::new();

    for y in 0..dimension {
        let mut input: String = String::new();
        io::stdin().read_line(&mut input).unwrap();

        let mut row: Vec<Cell> = Vec::with_capacity(dimension as usize);

        let mut x: u16 = 0;
        for str in input.split_whitespace() {
            let value = str.parse::<u32>().unwrap();
            row.push(Cell {
                value,
                possible_paths: 0
            });

            match coordinates_by_value.entry(value) {
                Entry::Occupied(entry) => { entry.into_mut().push((y, x)); }
                Entry::Vacant(entry) => { entry.insert(vec![(y, x)]); }
            }

            x += 1;
        }

        rows.push(row);
    }

    let mut values_sorted = coordinates_by_value.keys().collect::<Vec<&u32>>();
    values_sorted.sort();
    let last_value = values_sorted.last().unwrap();
    let mut sum: u32 = 0;
    for value in &values_sorted {
        if **value <= 1 { continue; }
        for (y, x) in &coordinates_by_value[value] {
            let x = *x as usize;
            let y = *y as usize;
            let mut path_counter = 0;

            // Vertical matches
            for (yi, row) in rows.iter().enumerate() {
                if yi == y { continue; }
                let cell = row.get(x).unwrap();
                if cell.value < **value {
                    path_counter = (path_counter + 1 + cell.possible_paths) % MOD;
                }
            }

            // Horizontal matches
            let column = rows.get(y).unwrap();
            for (xi, cell) in column.iter().enumerate() {
                if xi == x { continue; }
                if cell.value < **value {
                    path_counter = (path_counter + 1 + cell.possible_paths) % MOD;
                }
            }

            rows.get_mut(y).unwrap().get_mut(x).unwrap().possible_paths = path_counter;
            sum = (sum + path_counter) % MOD;
        }
    }

    println!("{:?}", rows);
    println!("{}", sum);
}

#[derive(Debug)]
struct Cell {
    value: u32,
    possible_paths: u32,
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
3
1 1 1
1 1 1
1 1 1

correct output
9

user output
[[Cell { value: 1, possible_pa...
Truncated

Test 2

Group: 1, 2, 3

Verdict:

input
3
1 2 3
6 5 4
7 8 9

correct output
135

user output
[[Cell { value: 1, possible_pa...
Truncated

Test 3

Group: 1, 2, 3

Verdict:

input
3
7 8 1
4 5 4
3 9 6

correct output
57

user output
[[Cell { value: 7, possible_pa...
Truncated

Test 4

Group: 2, 3

Verdict:

input
100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
10000

user output
[[Cell { value: 1, possible_pa...
Truncated

Test 5

Group: 2, 3

Verdict:

input
100
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
187458477

user output
[[Cell { value: 1, possible_pa...
Truncated

Test 6

Group: 2, 3

Verdict:

input
100
2995 8734 1018 2513 7971 5063 ...

correct output
964692694

user output
[[Cell { value: 2995, possible...
Truncated

Test 7

Group: 3

Verdict:

input
1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1000000

user output
(empty)

Test 8

Group: 3

Verdict:

input
1000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
229147081

user output
(empty)

Test 9

Group: 3

Verdict:

input
1000
520283 805991 492643 75254 527...

correct output
951147313

user output
(empty)