結果
問題 | No.325 マンハッタン距離2 |
ユーザー | koba-e964 |
提出日時 | 2016-03-23 17:45:33 |
言語 | Rust (1.77.0) |
結果 |
AC
|
実行時間 | 1 ms / 1,000 ms |
コード長 | 1,878 bytes |
コンパイル時間 | 561 ms |
コンパイル使用メモリ | 156,568 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-04-09 21:09:34 |
合計ジャッジ時間 | 1,541 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,944 KB |
testcase_05 | AC | 0 ms
6,940 KB |
testcase_06 | AC | 0 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 1 ms
6,940 KB |
testcase_15 | AC | 1 ms
6,944 KB |
testcase_16 | AC | 1 ms
6,940 KB |
testcase_17 | AC | 0 ms
6,940 KB |
testcase_18 | AC | 1 ms
6,940 KB |
testcase_19 | AC | 1 ms
6,944 KB |
testcase_20 | AC | 1 ms
6,940 KB |
testcase_21 | AC | 1 ms
6,940 KB |
testcase_22 | AC | 0 ms
6,940 KB |
testcase_23 | AC | 1 ms
6,944 KB |
testcase_24 | AC | 0 ms
6,944 KB |
testcase_25 | AC | 1 ms
6,940 KB |
testcase_26 | AC | 1 ms
6,944 KB |
ソースコード
#[allow(unused_imports)] use std::cmp::*; use std::io::*; #[allow(dead_code)] fn getline() -> String { let mut ret = String::new(); std::io::stdin().read_line(&mut ret).ok(); return ret; } #[allow(dead_code)] fn getword() -> String { let mut stdin = std::io::stdin(); let mut u8b: [u8; 1] = [0]; loop { let mut buf: Vec<u8> = Vec::with_capacity(16); loop { let res = stdin.read(&mut u8b); if res.is_err() ||u8b[0] <= ' ' as u8 { break; } else { buf.push(u8b[0]); } } if buf.len() >= 1 { let ret = std::string::String::from_utf8(buf).unwrap(); return ret; } } } #[allow(dead_code)] fn parse<T : std::str::FromStr>(s : &str) -> T { return s.parse::<T>().ok().unwrap(); } fn calc2(x: i64, y: i64, d: i64) -> i64 { if x < 0 && y < 0 { return calc(-x - 1, -y - 1, d) - calc(0, -y - 1, d) - calc(-x - 1, 0, d) + 1; } if x < 0 { return - calc(-x - 1, y, d) + calc(0, y, d); } if y < 0 { return calc(y, x, d); } assert!(x >= 0 && y >= 0); if x + y <= d { return (x + 1) * (y + 1); } if x > y { return calc(y, x, d); } assert!(x <= y); if d <= x { return (d + 1) * (d + 2) / 2; } if d <= y { return (2 * d - x + 2) * (x + 1) / 2; } let e = x + y - d; return (x + 1) * (y + 1) - e * (e + 1) / 2; } fn calc(x: i64, y: i64, d: i64) -> i64 { let res = calc2(x, y, d); return res; } fn main() { let (x1, y1): (i64, i64) = (parse(&getword()), parse(&getword())); let (x2, y2): (i64, i64) = (parse(&getword()), parse(&getword())); let d = parse(&getword()); println!("{}", calc(x2, y2, d) + calc(x1 - 1, y1 - 1, d) - calc(x2, y1 - 1, d) - calc(x1 - 1, y2, d)); }