結果
| 問題 |
No.2091 Shio Ramen (Easy)
|
| ユーザー |
|
| 提出日時 | 2025-04-24 11:53:03 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 1,728 bytes |
| コンパイル時間 | 13,420 ms |
| コンパイル使用メモリ | 400,352 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-04-24 11:53:18 |
| 合計ジャッジ時間 | 12,164 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
use std::{
cell::RefCell,
fmt::Debug,
io::{BufWriter, StdinLock, StdoutLock, stdin, stdout},
str::FromStr,
};
fn main() {
let [n, s, k] = read_tuple();
let mut a = vec![];
for _ in 0..n {
a.push(read::<i32>());
}
let mn = *a.iter().min_by_key(|x| x.abs_diff(s)).unwrap();
if mn.abs_diff(s) > k as u32 {
println!("Unlucky!");
} else {
println!("{}", a.iter().position(|x| *x == mn).unwrap() + 1);
}
}
thread_local! {
static STDIN: RefCell<StdinLock<'static>> = RefCell::new(stdin().lock());
static STDOUT: RefCell<BufWriter<StdoutLock<'static>>> = RefCell::new(BufWriter::new(stdout().lock()));
}
#[allow(dead_code)]
fn read<T: FromStr>() -> T
where
<T as FromStr>::Err: Debug,
{
read_line().parse().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T>
where
<T as FromStr>::Err: Debug,
{
read_line()
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect()
}
#[allow(dead_code)]
fn read_tuple<T: FromStr, const N: usize>() -> [T; N]
where
T: Debug,
<T as FromStr>::Err: Debug,
{
read_vec::<T>().try_into().unwrap()
}
fn read_line() -> String {
use std::io::BufRead;
let mut s = String::new();
STDIN.with(|cell| {
cell.borrow_mut().read_line(&mut s).unwrap();
});
String::from_str(s.trim_end()).unwrap()
}
#[macro_export]
macro_rules! print {
($($t:tt)*) => {
use std::io::Write;
STDOUT.with(|cell| write!(cell.borrow_mut(), $($t)*).unwrap())
};
}
#[macro_export]
macro_rules! println {
($($t:tt)*) => {
use std::io::Write;
STDOUT.with(|cell| writeln!(cell.borrow_mut(), $($t)*).unwrap())
};
}