結果
問題 | No.1650 Moving Coins |
ユーザー |
![]() |
提出日時 | 2021-08-20 22:02:13 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 292 ms / 2,000 ms |
コード長 | 1,562 bytes |
コンパイル時間 | 12,746 ms |
コンパイル使用メモリ | 376,036 KB |
実行使用メモリ | 23,196 KB |
最終ジャッジ日時 | 2024-10-14 03:41:57 |
合計ジャッジ時間 | 22,496 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
コンパイルメッセージ
warning: variable does not need to be mutable --> src/main.rs:20:9 | 20 | let mut a = read_vec::<i64>(); | ----^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default
ソースコード
#![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() }