結果
| 問題 | No.935 う し た ぷ に き あ く ん 笑 ビ - ム |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-18 18:06:30 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 1,599 bytes |
| 記録 | |
| コンパイル時間 | 13,561 ms |
| コンパイル使用メモリ | 391,384 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-27 23:12:57 |
| 合計ジャッジ時間 | 15,043 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 58 |
ソースコード
use std::io::Read;
use std::cmp::min;
fn solve(n: usize, s: Vec<String>, lives: Vec<usize>, queries: Vec<usize>) {
let enemy_count: usize = s.iter().filter(|a| a.as_str() == "E").count();
let mut life_summary: Vec<usize> = vec![std::usize::MAX; enemy_count+1];
life_summary[0] = 0;
for start in 0..n {
let mut enemy: usize = 0;
let mut tlife: usize = 0;
for i in start..n {
enemy += if s[i].as_str() == "E" { 1 } else { 0 };
tlife += lives[i];
life_summary[enemy] = min(life_summary[enemy], tlife);
}
}
queries.iter().for_each(|q| {
let result: usize = life_summary.iter().enumerate()
.find(|pair| pair.1 > q)
.map_or_else(|| enemy_count, |pair| pair.0 - 1);
println!("{}", result);
});
}
fn main() {
let mut all_data = String::new();
std::io::stdin().read_to_string(&mut all_data).ok();
let all_data: Vec<&str> = all_data.trim().split('\n').map(|l| l.trim()).collect();
let n: usize = all_data.iter().next().unwrap().parse::<usize>().unwrap();
let s: Vec<String> = all_data.iter().skip(1).next().unwrap().chars().map(|c| c.to_string()).collect();
let lives: Vec<usize> = all_data.iter().skip(2).next().unwrap().split_whitespace().map(|l| l.parse::<usize>().unwrap()).collect();
let _q: usize = all_data.iter().skip(3).next().unwrap().parse::<usize>().unwrap();
let queries: Vec<usize> = all_data.iter().skip(4).next().unwrap().split_whitespace().map(|l| l.parse::<usize>().unwrap()).collect();
solve(n, s, lives, queries);
}