結果

問題 No.1650 Moving Coins
ユーザー fukafukatanifukafukatani
提出日時 2021-08-20 22:02:13
言語 Rust
(1.77.0)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 1,562 bytes
コンパイル時間 1,253 ms
コンパイル使用メモリ 155,428 KB
実行使用メモリ 24,300 KB
最終ジャッジ日時 2023-08-04 06:33:59
合計ジャッジ時間 10,983 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 226 ms
4,928 KB
testcase_04 AC 171 ms
4,376 KB
testcase_05 AC 217 ms
4,660 KB
testcase_06 AC 244 ms
4,936 KB
testcase_07 AC 243 ms
4,920 KB
testcase_08 AC 254 ms
9,368 KB
testcase_09 AC 256 ms
7,960 KB
testcase_10 AC 256 ms
8,976 KB
testcase_11 AC 257 ms
9,452 KB
testcase_12 AC 245 ms
7,368 KB
testcase_13 AC 253 ms
7,368 KB
testcase_14 AC 251 ms
8,764 KB
testcase_15 AC 251 ms
7,200 KB
testcase_16 AC 260 ms
9,944 KB
testcase_17 AC 248 ms
10,144 KB
testcase_18 AC 261 ms
10,904 KB
testcase_19 AC 266 ms
11,184 KB
testcase_20 AC 274 ms
13,020 KB
testcase_21 AC 262 ms
12,284 KB
testcase_22 AC 285 ms
23,336 KB
testcase_23 AC 287 ms
24,300 KB
testcase_24 AC 243 ms
5,168 KB
testcase_25 AC 237 ms
5,172 KB
testcase_26 AC 22 ms
7,988 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable does not need to be mutable
  --> Main.rs:20:9
   |
20 |     let mut a = read_vec::<i64>();
   |         ----^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[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 n = read::<usize>();
    let mut a = read_vec::<i64>();
    let b = read_vec::<i64>();

    let mut opes = vec![vec![0]];
    for i in 1..n {
        if (a[i] <= b[i]) != (a[i - 1] <= b[i - 1]) {
            opes.push(vec![]);
        }
        let last = opes.len() - 1;
        opes[last].push(i);
    }
    debug!(opes);

    let mut answers = vec![];
    for ref mut block in &mut opes {
        if a[block[0]] <= b[block[0]] {
            block.reverse();
        }
        for &i in block.iter() {
            for _ in 0..(a[i] - b[i]).abs() {
                if a[i] <= b[i] {
                    answers.push((i, 'R'));
                } else {
                    answers.push((i, 'L'));
                }
            }
        }
    }

    println!("{}", answers.len());
    for (i, ch) in answers {
        println!("{} {}", i + 1, ch);
    }
}

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