結果
| 問題 |
No.1021 Children in Classrooms
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-26 12:33:07 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,382 bytes |
| コンパイル時間 | 30,153 ms |
| コンパイル使用メモリ | 378,692 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-16 20:34:17 |
| 合計ジャッジ時間 | 31,202 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 17 |
ソースコード
use std::collections::VecDeque;
fn main() {
let _n: u32 = read();
let _m: u32 = read();
let d: VecDeque<u32> = read::<String>()
.split_whitespace()
.map(|x| x.parse().unwrap())
.collect();
let s: String = read();
let r: String = solve(d, s);
println!("{}", r);
}
fn solve(d: VecDeque<u32>, s: String) -> String {
let mut e = d;
for c in s.chars() {
if c == 'L' {
let a: u32 = e.pop_front().unwrap();
let b: u32 = e.pop_front().unwrap();
e.push_front(a + b);
e.push_back(0);
} else {
let a: u32 = e.pop_back().unwrap();
let b: u32 = 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(" ")
}
use std::io::*;
use std::str::FromStr;
/// see https://qiita.com/tubo28/items/e6076e9040da57368845#%E5%85%A5%E5%87%BA%E5%8A%9B
fn read<T: FromStr>() -> T {
let stdin = stdin();
let stdin = stdin.lock();
let token: String = stdin
.bytes()
.map(|c| c.expect("failed to read char") as char)
.skip_while(|c| c.is_whitespace())
.take_while(|c| !c.is_whitespace())
.collect();
token.parse().ok().expect("failed to parse token")
}