結果
| 問題 |
No.1169 Row and Column and Diagonal
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2020-08-14 22:44:25 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,323 bytes |
| コンパイル時間 | 13,839 ms |
| コンパイル使用メモリ | 389,920 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-10-10 16:06:11 |
| 合計ジャッジ時間 | 18,088 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 TLE * 1 -- * 8 |
ソースコード
use std::io::Read;
fn read<T: std::str::FromStr>() -> T {
let token: String = std::io::stdin()
.bytes()
.map(|c| c.ok().unwrap() as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.collect();
token.parse().ok().unwrap()
}
fn solve(a: &mut Vec<Vec<usize>>, i: usize, j: usize) -> bool {
let n = a.len();
if i >= n {
return true;
}
let mut next_i = i;
let mut next_j = j + 1;
if next_j == n {
next_i = i + 1;
next_j = 0;
}
if i == j {
return solve(a, next_i, next_j);
}
let mut seen = std::collections::HashSet::new();
for k in 0..n {
seen.insert(a[k][j]);
seen.insert(a[i][k]);
}
let xs = (1..=n).filter(|x| !seen.contains(x));
for x in xs {
a[i][j] = x;
if solve(a, next_i, next_j) {
return true;
}
a[i][j] = 0;
}
return false;
}
fn main() {
let n: usize = read();
let mut a = vec![vec![0; n]; n];
for i in 0..n {
a[i][i] = i + 1;
}
assert!(solve(&mut a, 0, 0));
for r in a {
println!(
"{}",
r.iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.join(" ")
);
}
}
ikd