結果

問題 No.2559 眩しい数直線
ユーザー
提出日時 2024-05-11 23:43:44
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 665 bytes
コンパイル時間 13,694 ms
コンパイル使用メモリ 388,448 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-20 08:53:03
合計ジャッジ時間 14,980 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::{collections::HashMap, io::Read};

fn main() {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	let x: i16 = s
		.trim()
		.split(' ')
		.flat_map(str::parse)
		.collect::<Vec<i16>>()[1];
	s.clear();
	std::io::stdin().read_to_string(&mut s).ok();
	let mut h = HashMap::new();
	s.trim().split('\n').for_each(|s| {
		let n: Vec<i16> = s.split(' ').flat_map(str::parse).collect();
		let v = h.entry(n[0]).or_insert(n[1]);
		*v = n[1].max(*v);
	});
	let a = (1..=x)
		.map(|i| {
			h.iter()
				.map(|(a, b)| b - (a - i).abs())
				.max()
				.unwrap()
				.to_string()
		})
		.collect::<Vec<String>>()
		.join(" ");
	println!("{}", a)
}
0