結果
問題 |
No.1021 Children in Classrooms
|
ユーザー |
|
提出日時 | 2020-04-26 13:10:55 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 33 ms / 2,000 ms |
コード長 | 1,156 bytes |
コンパイル時間 | 13,277 ms |
コンパイル使用メモリ | 379,472 KB |
実行使用メモリ | 16,768 KB |
最終ジャッジ日時 | 2024-11-17 02:01:35 |
合計ジャッジ時間 | 15,470 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
use std::collections::VecDeque; use std::io::*; fn main() { // ref: https://yukicoder.me/submissions/462707 let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let _m: usize = itr.next().unwrap().parse().unwrap(); let d: VecDeque<usize> = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let s: String = itr.next().unwrap().to_string(); let r: String = solve(d, s); println!("{}", r); } fn solve(d: VecDeque<usize>, s: String) -> String { let mut e = d; for c in s.chars() { if c == 'L' { let a = e.pop_front().unwrap(); let b = e.pop_front().unwrap(); e.push_front(a + b); e.push_back(0); } else { let a = e.pop_back().unwrap(); let b = e.pop_back().unwrap(); e.push_back(a + b); e.push_front(0); } } e.iter() .map(|i| i.to_string()) .into_iter() .collect::<Vec<String>>() .join(" ") }