結果
| 問題 |
No.1767 BLUE to RED
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-26 23:31:30 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,599 bytes |
| コンパイル時間 | 12,465 ms |
| コンパイル使用メモリ | 384,552 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-29 18:35:32 |
| 合計ジャッジ時間 | 14,266 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 RE * 1 |
| other | WA * 14 RE * 7 |
ソースコード
use std::cmp::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
($($r:tt)*) => {
let stdin = std::io::stdin();
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
let mut next = move || -> String{
bytes.by_ref().map(|r|r.unwrap() as char)
.skip_while(|c|c.is_whitespace())
.take_while(|c|!c.is_whitespace())
.collect()
};
input_inner!{next, $($r)*}
};
}
macro_rules! input_inner {
($next:expr) => {};
($next:expr,) => {};
($next:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($next, $t);
input_inner!{$next $($r)*}
};
}
macro_rules! read_value {
($next:expr, [ $t:tt ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}
fn main() {
input! {
n: usize, m: usize,
a: [i64; n],
b: [i64; m],
}
const INF: i64 = 1 << 50;
let mut pos = 0;
let mut ans = INF;
for i in 0..n + 1 {
let lo = if i == 0 { -INF } else { a[i - 1] };
let hi = if i == n { INF } else { a[i] };
let mut dp = vec![lo];
while pos < n && b[pos] < hi {
dp.push(b[pos]);
pos += 1;
}
dp.push(hi);
let mut ma = 0;
for i in 0..dp.len() - 1 {
ma = max(ma, dp[i + 1] - dp[i]);
}
ans = min(ans, hi - lo - ma);
}
println!("{}", ans);
}