| Task: | Ruudukko |
| Sender: | Metabolix |
| Submission time: | 2025-09-26 18:58:37 +0300 |
| Language: | Rust (2021) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 100 |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | details |
Compiler report
warning: unnecessary parentheses around `if` condition
--> input/code.rs:20:12
|
20 | if (w * h == 1) {
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
20 - if (w * h == 1) {
20 + if w * h == 1 {
|
warning: unnecessary parentheses around `if` condition
--> input/code.rs:29:12
|
29 | if (w == 3 && h == 2) {
| ^ ^
|
help: remove these parentheses
|
29 - if (w == 3 && h == 2) {
29 + if w == 3 && h == 2 {
|
warning: 2 warnings emittedCode
use std::io;
// Lukee rivin syötettä ja palauttaa sen sisältämät luvut vektorina.
fn read_numbers() -> Vec<i64> {
let mut input = String::new();
io::stdin().read_line(&mut input).expect("Luku epäonnistui");
input
.trim()
.split_whitespace()
.map(|s| s.parse().expect("Ei kelvollinen luku"))
.collect()
}
fn main() {
let testejä = read_numbers()[0];
for _ in 0..testejä {
let koko = read_numbers();
let h = koko[0];
let w = koko[1];
if (w * h == 1) {
println!("YES");
println!("1");
continue;
}
if (w * h <= 3) || (w == 2 && h == 2) {
println!("NO");
continue;
}
if (w == 3 && h == 2) {
println!("YES");
println!("1 5 3");
println!("4 2 6");
continue;
}
let mut ruudukko: Vec<Vec<i64>> = (0..h).map(|_| (0..w).map(|_| 0).collect()).collect();
let mut i = 1;
for y in 0..h {
for x in 0..w {
if y % 2 != x % 2 {
ruudukko[y as usize][x as usize] = i;
i += 1;
}
}
}
for y in 0..h {
for x in 0..w {
if y % 2 == x % 2 {
ruudukko[y as usize][x as usize] = i;
i += 1;
}
}
}
println!("YES");
for rivi in ruudukko {
let riviteksti: Vec<String> = rivi.iter().map(|&n| n.to_string()).collect();
println!("{}", riviteksti.join(" "));
}
}
}
