結果

問題 No.1650 Moving Coins
ユーザー koba-e964koba-e964
提出日時 2021-08-20 22:40:03
言語 Rust
(1.77.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 2,651 bytes
コンパイル時間 1,660 ms
コンパイル使用メモリ 180,612 KB
実行使用メモリ 18,032 KB
最終ジャッジ日時 2024-04-22 05:33:36
合計ジャッジ時間 6,788 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 13 ms
5,376 KB
testcase_04 AC 10 ms
5,376 KB
testcase_05 AC 13 ms
5,376 KB
testcase_06 AC 14 ms
5,376 KB
testcase_07 AC 14 ms
5,376 KB
testcase_08 AC 44 ms
10,824 KB
testcase_09 AC 43 ms
10,584 KB
testcase_10 AC 46 ms
11,132 KB
testcase_11 AC 48 ms
11,848 KB
testcase_12 AC 34 ms
8,428 KB
testcase_13 AC 33 ms
8,560 KB
testcase_14 AC 44 ms
10,900 KB
testcase_15 AC 29 ms
7,696 KB
testcase_16 AC 49 ms
11,664 KB
testcase_17 AC 51 ms
11,676 KB
testcase_18 AC 57 ms
13,628 KB
testcase_19 AC 71 ms
18,032 KB
testcase_20 AC 74 ms
16,492 KB
testcase_21 AC 71 ms
17,204 KB
testcase_22 AC 72 ms
16,492 KB
testcase_23 AC 71 ms
16,384 KB
testcase_24 AC 15 ms
5,376 KB
testcase_25 AC 14 ms
5,376 KB
testcase_26 AC 38 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
    input! {
        n: usize,
        a: [i64; n],
        b: [i64; n],
    }
    let mut ev = vec![];
    for i in 0..n {
        ev.push((a[i], i));
        ev.push((b[i], n + i));
    }
    ev.sort();
    let mut del = 0;
    let mut ops = vec![];
    let mut cur = vec![];
    for i in 0..2 * n {
        let (_, y) = ev[i];
        let old = del;
        if y >= n {
            del -= 1;
        } else {
            del += 1;
            cur.push(y);
        }
        if del == 0 {
            if old > 0 {
                cur.reverse();
                for c in cur.drain(..) {
                    for _ in a[c]..b[c] {
                        ops.push((c, 0));
                    }
                }
            } else {
                for c in cur.drain(..) {
                    for _ in b[c]..a[c] {
                        ops.push((c, 1));
                    }
                }
            }
        }
    }
    puts!("{}\n", ops.len());
    for (x, y) in ops {
        puts!("{} {}\n", x + 1, if y == 0 { 'R' } else { 'L' });
    }
}
0