結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-30 17:02:50 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 2,000 ms |
| コード長 | 1,341 bytes |
| コンパイル時間 | 12,993 ms |
| コンパイル使用メモリ | 377,512 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-16 04:03:22 |
| 合計ジャッジ時間 | 13,586 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
ソースコード
use std::io::*;
fn main() {
let mut s: String = String::new();
std::io::stdin().read_to_string(&mut s).ok();
let mut itr = s.trim().split_whitespace();
let n: usize = itr.next().unwrap().parse().unwrap();
for _ in 0..n {
let mut a: usize = itr.next().unwrap().parse().unwrap();
let b: usize = itr.next().unwrap().parse().unwrap();
let mut c: usize = itr.next().unwrap().parse().unwrap();
let mut ans = 1 << 60;
let mut cnt = 0;
if a < c {
std::mem::swap(&mut a, &mut c);
}
if a == c {
c -= 1;
cnt += 1;
}
if c == 0 {
println!("-1",);
continue;
}
// b max
if (b > a && b > c) || (a > b && c > b) {
println!("{}", cnt);
continue;
}
if c - 1 > 0 {
ans = std::cmp::min(ans, cnt + (b - (c - 1)));
}
let mut tmp = 0;
if b - 1 > 0 {
tmp += a - (b - 1);
if c == b - 1 {
tmp += 1;
c -= 1;
}
if c != 0 {
ans = std::cmp::min(ans, cnt + tmp);
}
}
if ans != (1 << 60) {
println!("{}", ans);
} else {
println!("-1",);
}
}
}