CSES - Datatähti 2023 alku - Results
Submission details
Task:Ruudukko
Sender:EmuBird
Submission time:2022-11-06 20:59:46 +0200
Language:Rust
Status:READY
Result:61
Feedback
groupverdictscore
#1ACCEPTED28
#2ACCEPTED33
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#2ACCEPTED0.00 s1, 2, 3details
#3ACCEPTED0.00 s1, 2, 3details
#4ACCEPTED0.00 s2, 3details
#5ACCEPTED0.01 s2, 3details
#6ACCEPTED0.02 s2, 3details
#7ACCEPTED0.04 s3details
#8--3details
#9--3details

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 mut sum: u32 = 0;
let last_value = values_sorted.last().unwrap();
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;
}
}
if value != last_value {
rows.get_mut(y).unwrap().get_mut(x).unwrap().possible_paths = path_counter;
}
sum = (sum + path_counter) % MOD;
}
}
sum = (sum + (dimension as u32 * dimension as u32)) % MOD;
println!("{}", sum);
}
struct Cell {
value: u32,
possible_paths: u32,
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
1 1 1
1 1 1
1 1 1

correct output
9

user output
9

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
1 2 3
6 5 4
7 8 9

correct output
135

user output
135

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
7 8 1
4 5 4
3 9 6

correct output
57

user output
57

Test 4

Group: 2, 3

Verdict: ACCEPTED

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

correct output
10000

user output
10000

Test 5

Group: 2, 3

Verdict: ACCEPTED

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

correct output
187458477

user output
187458477

Test 6

Group: 2, 3

Verdict: ACCEPTED

input
100
2995 8734 1018 2513 7971 5063 ...

correct output
964692694

user output
964692694

Test 7

Group: 3

Verdict: ACCEPTED

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

correct output
1000000

user output
1000000

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)