結果
| 問題 |
No.48 ロボットの操縦
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-03 15:19:50 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 1,137 bytes |
| コンパイル時間 | 12,673 ms |
| コンパイル使用メモリ | 377,528 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-23 18:44:29 |
| 合計ジャッジ時間 | 12,422 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
ソースコード
use std::io::{self, Read};
#[derive(Debug)]
struct Input {
x: i32,
y: i32,
l: i32,
}
fn next_token(cin_lock: &mut io::StdinLock) -> String {
cin_lock
.by_ref()
.bytes()
.map(|c| c.unwrap() as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.collect::<String>()
}
fn read_input(cin_lock: &mut io::StdinLock) -> Input {
Input {
x: next_token(cin_lock).parse().unwrap(),
y: next_token(cin_lock).parse().unwrap(),
l: next_token(cin_lock).parse().unwrap(),
}
}
fn solve(input: Input, _cin_lock: &mut io::StdinLock) {
let n_turns = if input.y < 0 {
2
} else if input.x != 0 {
1
} else {
0
};
let move_horizontal = (input.x.abs() + (input.l - 1)) / input.l;
let move_vertical = (input.y.abs() + (input.l - 1)) / input.l;
let answer = n_turns + move_horizontal + move_vertical;
println!("{}", answer);
}
fn main() {
let cin = io::stdin();
let mut cin_lock = cin.lock();
let input = read_input(&mut cin_lock);
solve(input, &mut cin_lock);
}