結果
| 問題 |
No.1021 Children in Classrooms
|
| コンテスト | |
| ユーザー |
fukafukatani
|
| 提出日時 | 2020-04-10 21:45:23 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 2,000 ms |
| コード長 | 2,026 bytes |
| コンパイル時間 | 14,009 ms |
| コンパイル使用メモリ | 376,600 KB |
| 実行使用メモリ | 6,300 KB |
| 最終ジャッジ日時 | 2024-09-15 19:50:02 |
| 合計ジャッジ時間 | 14,917 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
コンパイルメッセージ
warning: unused variable: `m` --> src/main.rs:20:13 | 20 | let (n, m) = (v[0], v[1]); | ^ help: if this is intentional, prefix it with an underscore: `_m` | = note: `#[warn(unused_variables)]` on by default
ソースコード
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
#[allow(unused_macros)]
macro_rules! debug {
($($e:expr),*) => {
#[cfg(debug_assertions)]
$({
let (e, mut err) = (stringify!($e), std::io::stderr());
writeln!(err, "{} = {:?}", e, $e).unwrap()
})*
};
}
fn main() {
let v = read_vec::<usize>();
let (n, m) = (v[0], v[1]);
let a = read_vec::<i64>();
let s = read::<String>().chars().collect::<Vec<_>>();
let mut cur_0 = 0;
for &ch in &s {
if ch == 'L' {
if cur_0 > 0 {
cur_0 -= 1;
}
} else if ch == 'R' {
if cur_0 < n - 1 {
cur_0 += 1;
}
}
}
let mut a = a.into_iter().collect::<VecDeque<_>>();
let mut count = 0i64;
let mut min_count = 0i64;
let mut max_count = 0i64;
for &ch in &s {
if ch == 'L' {
count -= 1;
} else if ch == 'R' {
count += 1;
}
if count < min_count {
min_count = count;
if a.len() > 1 {
let f = a.pop_front().unwrap();
a[0] += f;
}
}
if count > max_count {
max_count = count;
if a.len() > 1 {
let f = a.pop_back().unwrap();
let idx = a.len() - 1;
a[idx] += f;
}
}
}
let mut answers = vec![0; n];
for i in cur_0..cur_0 + a.len() {
answers[i] = a[i - cur_0];
}
for i in 0..n - 1 {
print!("{} ", answers[i]);
}
println!("{}", answers[n - 1]);
}
fn read<T: std::str::FromStr>() -> T {
let mut s = String::new();
std::io::stdin().read_line(&mut s).ok();
s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
read::<String>()
.split_whitespace()
.map(|e| e.parse().ok().unwrap())
.collect()
}
fukafukatani