結果
問題 | No.489 株に挑戦 |
ユーザー | cympfh |
提出日時 | 2017-02-26 00:09:36 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,807 bytes |
コンパイル時間 | 12,296 ms |
コンパイル使用メモリ | 402,500 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-06-11 15:16:16 |
合計ジャッジ時間 | 14,031 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 1 ms
6,940 KB |
testcase_26 | AC | 41 ms
7,296 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 1 ms
6,944 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
コンパイルメッセージ
warning: unused macro definition: `trace` --> src/main.rs:7:14 | 7 | macro_rules! trace { | ^^^^^ | = note: `#[warn(unused_macros)]` on by default warning: unused macro definition: `swap` --> src/main.rs:12:14 | 12 | macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) } | ^^^^ warning: variable `k` is assigned to, but never used --> src/main.rs:17:32 | 17 | let mut m = 1; let mut k = 1; | ^ | = note: consider using `_k` instead = note: `#[warn(unused_variables)]` on by default warning: methods `update`, `add`, and `at` are never used --> src/main.rs:60:8 | 14 | impl RMQ { | -------- methods in this implementation ... 60 | fn update(&mut self, idx: usize, x: i32) { | ^^^^^^ ... 71 | fn add(&mut self, idx: usize, x: i32) { | ^^^ ... 76 | fn at(&self, idx: usize) -> i32 { | ^^ | = note: `#[warn(dead_code)]` on by default
ソースコード
#![allow(unused_imports)] use std::io::{ self, Write }; use std::str::FromStr; use std::cmp::{ min, max }; use std::collections::{ BinaryHeap, VecDeque }; macro_rules! trace { ($var:expr) => ({ let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var); }) } macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) } struct RMQ {heap: Vec<i32>, size: usize, lefts: Vec<usize>, rights: Vec<usize>} impl RMQ { fn alignment(n: usize) -> usize { let mut m = 1; let mut k = 1; while n > m { k += 1; m *= 2; } m * 2 - 1 } fn of_left(idx: usize, base: usize) -> usize { let mut i = idx; while i < base { i = i * 2 + 1; } i - base } fn of_right(idx: usize, base: usize) -> usize { let mut i = idx; while i < base { i = i * 2 + 2; } i - base } fn new(v: &Vec<i32>) -> RMQ { let n = v.len(); let size = RMQ::alignment(n); let mut heap = vec![0; size]; for i in 0..n { heap[i + size/2] = v[i]; } for i in (0..size/2).rev() { heap[i] = max(heap[i*2+1], heap[i*2+2]); } let lefts = (0..size).map(|i| RMQ::of_left(i, size/2)).collect(); let rights = (0..size).map(|i| RMQ::of_right(i, size/2)).collect(); RMQ {heap: heap, size: size, lefts: lefts, rights: rights} } // max [left..right] inclusively fn max(&self, left: usize, right: usize) -> i32 { if left > right { return 0 } if left == right { return self.heap[self.size/2 + left] } let mut i = self.size/2 + left; loop { let parent = (i - 1) / 2; if self.lefts[parent] == left && self.rights[parent] <= right { i = parent; } else { break } } max(self.heap[i], self.max(self.rights[i] + 1, right)) } // [idx] <- x fn update(&mut self, idx: usize, x: i32) { let mut i = idx + self.size/2; self.heap[i] = x; loop { i = (i - 1) / 2; if i == 0 { break } self.heap[i] = max(self.heap[i*2+1], self.heap[i*2+2]); } } // [idx] <- [idx] + x fn add(&mut self, idx: usize, x: i32) { let z = self.heap[idx + self.size/2] + x; self.update(idx, z); } fn at(&self, idx: usize) -> i32 { self.heap[idx + self.size/2] } } fn main() { let mut sc = Scanner::new(); let n: usize = sc.cin(); let d: usize = sc.cin(); let k: i32 = sc.cin(); let xs = (0..n).map(|_| sc.cin()).collect::<Vec<i32>>(); let rmq = RMQ::new(&xs); let mut ans = 0; for i in 0..(n-1) { let mx = rmq.max(i + 1, min(i + d, n - 1)); ans = max(ans, mx - xs[i]); } println!("{}", ans * k); } #[allow(dead_code)] struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, } #[allow(dead_code)] impl Scanner { fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } } fn reserve(&mut self) { while self.buffer.len() == 0 { let mut line = String::new(); let _ = self.stdin.read_line(&mut line); for w in line.split_whitespace() { self.buffer.push_back(String::from(w)); } } } fn cin<T: FromStr>(&mut self) -> T { self.reserve(); match self.buffer.pop_front().unwrap().parse::<T>() { Ok(a) => a, Err(_) => panic!("parse err") } } fn get_char(&mut self) -> char { self.reserve(); let head = self.buffer[0].chars().nth(0).unwrap(); let tail = String::from( &self.buffer[0][1..] ); if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); } head } }