結果

問題 No.1021 Children in Classrooms
ユーザー fukafukatanifukafukatani
提出日時 2020-04-10 21:45:23
言語 Rust
(1.77.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 2,026 bytes
コンパイル時間 4,929 ms
コンパイル使用メモリ 153,508 KB
実行使用メモリ 6,208 KB
最終ジャッジ日時 2023-10-13 23:57:07
合計ジャッジ時間 6,835 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 31 ms
6,204 KB
testcase_10 AC 32 ms
6,208 KB
testcase_11 AC 32 ms
6,152 KB
testcase_12 AC 30 ms
6,160 KB
testcase_13 AC 31 ms
6,104 KB
testcase_14 AC 31 ms
6,120 KB
testcase_15 AC 23 ms
4,464 KB
testcase_16 AC 22 ms
4,536 KB
testcase_17 AC 23 ms
4,488 KB
testcase_18 AC 29 ms
5,628 KB
testcase_19 AC 4 ms
4,372 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `m`
  --> 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

warning: 1 warning emitted

ソースコード

diff #

#![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()
}
0