結果
問題 | No.351 市松スライドパズル |
ユーザー |
|
提出日時 | 2016-03-15 18:58:18 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 253 ms / 2,000 ms |
コード長 | 1,386 bytes |
コンパイル時間 | 12,444 ms |
コンパイル使用メモリ | 404,112 KB |
実行使用メモリ | 9,696 KB |
最終ジャッジ日時 | 2024-10-01 06:37:23 |
合計ジャッジ時間 | 16,231 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 |
コンパイルメッセージ
warning: unused import: `std::cmp::*` --> src/main.rs:1:5 | 1 | use std::cmp::*; | ^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: function `getline` is never used --> src/main.rs:3:4 | 3 | fn getline() -> String { | ^^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: unused `Result` that must be used --> src/main.rs:14:13 | 14 | stdin.read(&mut u8b); | ^^^^^^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled = note: `#[warn(unused_must_use)]` on by default help: use `let _ = ...` to ignore the resulting value | 14 | let _ = stdin.read(&mut u8b); | +++++++
ソースコード
use std::cmp::*; use std::io::*; fn getline() -> String { let mut ret = String::new(); std::io::stdin().read_line(&mut ret).ok(); return ret; } fn getword() -> String { let mut stdin = std::io::stdin(); loop { let mut buf: Vec<u8> = Vec::with_capacity(16); let mut u8b: [u8; 1] = [0]; loop { stdin.read(&mut u8b); if u8b[0] <= ' ' as u8 { break; } else { buf.push(u8b[0]); } } let ret = std::string::String::from_utf8(buf).unwrap(); if ret.len() >= 1 { return ret; } } } fn parse<T : std::str::FromStr>(s : &str) -> T { match s.parse::<T>() { Ok(t) => t, _ => panic!(), } } fn main() { let h: i32 = parse(&getword()); let w: i32 = parse(&getword()); let n: usize = parse(&getword()); let mut s = vec![' '; n]; let mut k = vec![0; n]; let mut x = 0; let mut y = 0; for i in 0 .. n { s[i] = getword().chars().nth(0).unwrap(); k[i] = parse(&getword()); } for i in (0 .. n).rev() { match s[i] { 'R' => if y == k[i] { x = (x + w - 1) % w }, 'C' => if x == k[i] { y = (y + h - 1) % h }, _ => panic!(), }; } println!("{}", if (x + y) % 2 == 0 { "white" } else { "black" }); }