結果
問題 |
No.1110 好きな歌
|
ユーザー |
|
提出日時 | 2020-07-16 23:03:42 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 272 ms / 5,000 ms |
コード長 | 1,121 bytes |
コンパイル時間 | 13,276 ms |
コンパイル使用メモリ | 383,216 KB |
実行使用メモリ | 12,244 KB |
最終ジャッジ日時 | 2024-11-25 12:05:25 |
合計ジャッジ時間 | 22,264 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
use std::collections::VecDeque; fn main() { let mut nd = String::new(); std::io::stdin().read_line(&mut nd).ok(); let nd: Vec<usize> = nd.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nd[0]; let d = nd[1]; let mut a: Vec<usize> = vec![]; let mut idx2val: Vec<(usize, usize)> = vec![]; for i in 0..n { let mut ai = String::new(); std::io::stdin().read_line(&mut ai).ok(); let ai: usize = ai.trim().parse().unwrap(); a.push(ai); idx2val.push((i, ai)); } idx2val.sort_by_key(|pair| pair.1); let mut stack: VecDeque<(usize, usize)> = VecDeque::new(); let mut result: Vec<usize> = vec![0; n]; while let Some(pair) = idx2val.pop() { stack.push_back(pair); while stack.len() > 1 { let f = stack.front().unwrap(); if f.1 >= d + pair.1 { let f = stack.pop_front().unwrap(); result[f.0] = idx2val.len() + 1; } else { break; } } } result.iter().for_each(|i| { println!("{}", i); }); }