結果
問題 | No.2112 All 2x2 are Equal |
ユーザー |
![]() |
提出日時 | 2022-10-28 22:14:04 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 2,365 bytes |
コンパイル時間 | 20,598 ms |
コンパイル使用メモリ | 399,156 KB |
実行使用メモリ | 17,700 KB |
最終ジャッジ日時 | 2024-07-06 01:24:01 |
合計ジャッジ時間 | 16,237 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
ソースコード
use std::collections::VecDeque;macro_rules! get {($t:ty) => {{let mut line: String = String::new();std::io::stdin().read_line(&mut line).unwrap();line.trim().parse::<$t>().unwrap()}};($($t:ty),*) => {{let mut line: String = String::new();std::io::stdin().read_line(&mut line).unwrap();let mut iter = line.split_whitespace();($(iter.next().unwrap().parse::<$t>().unwrap(),)*)}};($t:ty; $n:expr) => {(0..$n).map(|_|get!($t)).collect::<Vec<_>>()};($($t:ty),*; $n:expr) => {(0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()};($t:ty ;;) => {{let mut line: String = String::new();std::io::stdin().read_line(&mut line).unwrap();line.split_whitespace().map(|t| t.parse::<$t>().unwrap()).collect::<Vec<_>>()}};($t:ty ;; $n:expr) => {(0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()};}fn main() {let (height, width) = get!(usize, usize);let mut queue = VecDeque::new();for i in 0..(height * width) {queue.push_back(i + 1);}let mut matrix = vec![vec![0; width]; height];for row in 0..height {for col in 0..width {if (row + col) % 2 == 0 {matrix[row][col] = queue.pop_front().unwrap();} else {matrix[row][col] = queue.pop_back().unwrap();}}}let sum = matrix[0][0] + matrix[0][1] + matrix[1][0] + matrix[1][1];for row in 0..(height - 1) {for col in 0..(width - 1) {let mut s = 0;for dr in 0..2 {for dc in 0..2 {s += matrix[row + dr][col + dc];}}if s != sum {println!("No");return;}}}println!("Yes");for row in 0..height {print!("{}", matrix[row][0]);for col in 1..width {print!(" {}", matrix[row][col]);}println!();}}