結果
問題 | No.59 鉄道の旅 |
ユーザー | mio_h |
提出日時 | 2017-02-20 22:25:03 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,398 bytes |
コンパイル時間 | 13,085 ms |
コンパイル使用メモリ | 406,560 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-09 16:48:37 |
合計ジャッジ時間 | 13,946 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,812 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 22 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 7 ms
6,944 KB |
testcase_09 | WA | - |
testcase_10 | AC | 7 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 13 ms
6,944 KB |
testcase_13 | WA | - |
testcase_14 | AC | 17 ms
6,944 KB |
testcase_15 | WA | - |
コンパイルメッセージ
warning: use of deprecated method `std::error::Error::description`: use the Display impl or to_string() --> src/main.rs:95:62 | 95 | Err(why) => panic!("error in read_line: {}", why.description()), | ^^^^^^^^^^^ | = note: `#[warn(deprecated)]` on by default
ソースコード
use std::io::{self, Stdin}; use std::str::{self, FromStr}; use std::error::Error; use std::thread; fn exec() { let mut sc = Scanner::new(); let n: usize = sc.ne(); let k: i32 = sc.ne(); let w: Vec<i32> = (0..n).map(|_| sc.ne()).collect(); let &ma = w.iter().max().unwrap(); let n = ma as usize; let mut fwt = FenwickTree::new(n + 1, 0i32); for x in w { if x < 0 { let id = (x * -1) as usize; let num = fwt.sum(id + 1) - fwt.sum(id); if num > 0 { fwt.add(id, -1); } } else { let id = x as usize; let num = fwt.sum(n + 1) - fwt.sum(id); if num < k { fwt.add(id, 1); } } } println!("{}", fwt.sum(n + 1)); } struct FenwickTree<T> { zero: T, n: usize, data: Vec<T>, } use std::ops::AddAssign; impl<T: Copy + AddAssign> FenwickTree<T> { fn new(n_: usize, z_: T) -> FenwickTree<T> { FenwickTree { zero: z_, n: n_, data: vec![z_; n_], } } //sum of [0, j) fn sum(&self, j: usize) -> T { let mut res = self.zero; let mut x = j as i64 - 1; while x >= 0 { res += self.data[x as usize]; x = (x & (x + 1)) - 1; } res } // add w to a[j] fn add(&mut self, j: usize, w: T) { let mut x = j; while x < self.n { self.data[x] += w; x |= x + 1; } } } fn main() { const DEFAULT_STACK: usize = 16 * 1024 * 1024; let builder = thread::Builder::new(); let th = builder.stack_size(DEFAULT_STACK); let handle = th.spawn(|| { exec(); }).unwrap(); let _ = handle.join(); } #[allow(dead_code)] struct Scanner { stdin: Stdin, id: usize, buf: Vec<u8>, } #[allow(dead_code)] impl Scanner { fn new() -> Scanner { Scanner { stdin: io::stdin(), id: 0, buf: Vec::new(), } } fn next_line(&mut self) -> Option<String> { let mut res = String::new(); match self.stdin.read_line(&mut res) { Ok(0) => return None, Ok(_) => Some(res), Err(why) => panic!("error in read_line: {}", why.description()), } } fn next<T: FromStr>(&mut self) -> Option<T> { while self.buf.len() == 0 { self.buf = match self.next_line() { Some(r) => { self.id = 0; r.trim().as_bytes().to_owned() } None => return None, }; } let l = self.id; assert!(self.buf[l] != b' '); let n = self.buf.len(); let mut r = l; while r < n && self.buf[r] != b' ' { r += 1; } let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() { Ok(s) => Some(s), Err(_) => { panic!("parse error, {:?}", String::from_utf8(self.buf[l..r].to_owned())) } }; while r < n && self.buf[r] == b' ' { r += 1; } if r == n { self.buf.clear(); } else { self.id = r; } res } fn ne<T: FromStr>(&mut self) -> T { self.next::<T>().unwrap() } }