結果
問題 | No.1008 Bench Craftsman |
ユーザー | akiradeveloper |
提出日時 | 2020-03-07 15:32:05 |
言語 | Rust (1.77.0 + proconio) |
結果 |
RE
|
実行時間 | - |
コード長 | 10,018 bytes |
コンパイル時間 | 12,488 ms |
コンパイル使用メモリ | 379,572 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2024-10-14 15:44:59 |
合計ジャッジ時間 | 14,571 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | AC | 115 ms
7,040 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 132 ms
5,248 KB |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | AC | 14 ms
5,248 KB |
testcase_16 | RE | - |
testcase_17 | AC | 14 ms
5,248 KB |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
コンパイルメッセージ
warning: unused variable: `y` --> src/main.rs:220:31 | 220 | pub fn upper_bound(&self, y: i64) -> i64 { | ^ help: if this is intentional, prefix it with an underscore: `_y` | = note: `#[warn(unused_variables)]` on by default warning: unused variable: `b` --> src/main.rs:244:13 | 244 | let b = line.b; | ^ help: if this is intentional, prefix it with an underscore: `_b` warning: field `n` is never read --> src/main.rs:225:5 | 224 | struct Imosu1d { | ------- field in this struct 225 | n: usize, | ^ | = note: `#[warn(dead_code)]` on by default warning: unused `Result` that must be used --> src/main.rs:134:9 | 134 | writeln!(out,"-1"); | ^^^^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled = note: `#[warn(unused_must_use)]` on by default = note: this warning originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info) warning: unused `Result` that must be used --> src/main.rs:150:9 | 150 | writeln!(out,"0"); | ^^^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled = note: this warning originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info) warning: unused `Result` that must be used --> src/main.rs:182:5 | 182 | writeln!(out,"{}",r); | ^^^^^^^^^^^^^^^^^^^^ | = note: this `Result` may be an `Err` variant, which should be handled = note: this warning originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info) warning: variable `L` should have a snake case name --> src/main.rs:253:13 | 253 | let L = r - (l+1); | ^ help: convert the identifier to snake case: `l` | = note: `#[warn(non_snake_case)]` on by default
ソースコード
#[doc = " https://github.com/hatoo/competitive-rust-snippets"] #[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::iter::FromIterator; #[macro_export] macro_rules ! chmax { ( $ x : expr , $ ( $ v : expr ) ,+ ) => { $ ( $ x = std :: cmp :: max ( $ x ,$ v ) ; ) + } ; } #[macro_export] macro_rules ! chmin { ( $ x : expr , $ ( $ v : expr ) ,+ ) => { $ ( $ x = std :: cmp :: min ( $ x ,$ v ) ; ) + } ; } #[macro_export] macro_rules ! max { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ xs : expr ) ,+ ) => { std :: cmp :: max ( $ x , max ! ( $ ( $ xs ) ,+ ) ) } ; } #[macro_export] macro_rules ! min { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ xs : expr ) ,+ ) => { std :: cmp :: min ( $ x , min ! ( $ ( $ xs ) ,+ ) ) } ; } #[macro_export] macro_rules ! dvec { ( $ t : expr ; $ len : expr ) => { vec ! [ $ t ; $ len ] } ; ( $ t : expr ; $ len : expr , $ ( $ rest : expr ) ,* ) => { vec ! [ dvec ! ( $ t ; $ ( $ rest ) ,* ) ; $ len ] } ; } #[macro_export] macro_rules ! cfor { ( ; $ ( $ rest : tt ) * ) => { cfor ! ( ( ) ; $ ( $ rest ) * ) } ; ( $ ( $ init : stmt ) ,+; ; $ ( $ rest : tt ) * ) => { cfor ! ( $ ( $ init ) ,+; ! false ; $ ( $ rest ) * ) } ; ( $ ( $ init : stmt ) ,+; $ cond : expr ; ; $ body : block ) => { cfor ! { $ ( $ init ) ,+; $ cond ; ( ) ; $ body } } ; ( $ ( $ init : stmt ) ,+; $ cond : expr ; $ ( $ step : expr ) ,+; $ body : block ) => { { $ ( $ init ; ) + while $ cond { let mut _first = true ; let mut _continue = false ; loop { if ! _first { _continue = true ; break } _first = false ; $ body } if ! _continue { break } $ ( $ step ; ) + } } } ; } #[doc = " main"] #[allow(unused_imports)] use std::io::{stdin, stdout, BufWriter, Write}; #[macro_export] macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut parser = Parser :: from_str ( $ s ) ; input_inner ! { parser , $ ( $ r ) * } } ; ( parser = $ parser : ident , $ ( $ r : tt ) * ) => { input_inner ! { $ parser , $ ( $ r ) * } } ; ( new_stdin_parser = $ parser : ident , $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let reader = std :: io :: BufReader :: new ( stdin . lock ( ) ) ; let mut $ parser = Parser :: new ( reader ) ; input_inner ! { $ parser , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { input ! { new_stdin_parser = parser , $ ( $ r ) * } } ; } #[macro_export] macro_rules ! input_inner { ( $ parser : ident ) => { } ; ( $ parser : ident , ) => { } ; ( $ parser : ident , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ parser , $ t ) ; input_inner ! { $ parser $ ( $ r ) * } } ; } #[macro_export] macro_rules ! read_value { ( $ parser : ident , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ parser , $ t ) ) ,* ) } ; ( $ parser : ident , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ parser , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ parser : ident , chars ) => { read_value ! ( $ parser , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ parser : ident , usize1 ) => { read_value ! ( $ parser , usize ) - 1 } ; ( $ parser : ident , $ t : ty ) => { $ parser . next ::<$ t > ( ) . expect ( "Parse error" ) } ; } use std::io; use std::io::BufRead; use std::str; pub struct Parser<R> { reader: R, buf: Vec<u8>, pos: usize, } impl Parser<io::Empty> { pub fn from_str(s: &str) -> Parser<io::Empty> { Parser { reader: io::empty(), buf: s.as_bytes().to_vec(), pos: 0, } } } impl<R: BufRead> Parser<R> { pub fn new(reader: R) -> Parser<R> { Parser { reader: reader, buf: vec![], pos: 0, } } pub fn update_buf(&mut self) { self.buf.clear(); self.pos = 0; loop { let (len, complete) = { let buf2 = self.reader.fill_buf().unwrap(); self.buf.extend_from_slice(buf2); let len = buf2.len(); if len == 0 { break; } (len, buf2[len - 1] <= 0x20) }; self.reader.consume(len); if complete { break; } } } pub fn next<T: str::FromStr>(&mut self) -> Result<T, T::Err> { loop { let mut begin = self.pos; while begin < self.buf.len() && (self.buf[begin] <= 0x20) { begin += 1; } let mut end = begin; while end < self.buf.len() && (self.buf[end] > 0x20) { end += 1; } if begin != self.buf.len() { self.pos = end; return str::from_utf8(&self.buf[begin..end]).unwrap().parse::<T>(); } else { self.update_buf(); } } } } #[allow(unused_macros)] macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } } #[doc = " https://github.com/hatoo/competitive-rust-snippets"] const BIG_STACK_SIZE: bool = true; #[allow(dead_code)] fn main() { use std::thread; if BIG_STACK_SIZE { thread::Builder::new() .stack_size(32 * 1024 * 1024) .name("solve".into()) .spawn(solve) .unwrap() .join() .unwrap(); } else { solve(); } } fn solve() { let out = stdout(); let mut out = BufWriter::new(out.lock()); input!{ n:usize,m:usize, a:[i64;n], xw:[(usize,i64);m], } // c=infでもだめか? let mut rem = a.clone(); for i in 0..m { let (x,w) = xw[i]; let x = x-1; rem[x] -= w; } let mut ok = true; for i in 0..n { if rem[i] <= 0 { ok = false; } } if !ok { writeln!(out,"-1"); return } // c=0でおっけーか? let mut tot = 0; for i in 0..m { tot += xw[i].1; } let mut ok = true; for i in 0..n { if tot >= a[i] { ok = false } } if ok { writeln!(out,"0"); return } let qu = |c:i64| { let mut imos = Imosu1d::new(n); for i in 0..m { let (x,w) = xw[i]; let x = x-1; let leftline = ArithSeq::from_point(x as i64, w, c); let r = max(0, leftline.lower_bound(0)) as usize; imos.add_line(r, x, leftline); let rightline = ArithSeq::from_point(x as i64, w, -c); let r = min(n as i64, rightline.lower_bound(0)) as usize; imos.add_line(x, r, rightline); } imos.build(); let mut ok = true; for i in 0..n { let sum = imos.get(i); if sum >= a[i] { ok = false; } } ok }; let mut bs = BinarySearch { lower: 1, upper: 1<<60, p: qu, }; let r = bs.lower_bound(); writeln!(out,"{}",r); } pub struct ArithSeq { pub a: i64, pub b: i64, } impl ArithSeq { #[doc = "y=ax+b"] pub fn new(a: i64, b: i64) -> Self { ArithSeq { a: a, b: b } } pub fn from_point(x0: i64, y0: i64, a: i64) -> Self { let b = y0 - a * x0; Self::new(a, b) } pub fn y(&self, x: i64) -> i64 { self.a * x + self.b } #[doc = "x such that f(x) >= y and f(x-1) < y"] pub fn lower_bound(&self, y: i64) -> i64 { assert!(self.a != 0); let a = self.a; let b = self.b; if a > 0 { let mut x = y - b; if x >= 0 { x += a - 1; } else { } let x = x / a; x } else { let y = 2 * b - y; let mirror = Self::new(-a, b); mirror.lower_bound(y) } } #[doc = "x such that f(x) < y and f(x+1) >= y"] pub fn upper_bound(&self, y: i64) -> i64 { unimplemented!() } } struct Imosu1d { n: usize, dp1: Vec<i64>, dp2: Vec<i64>, dp3: Vec<i64>, } impl Imosu1d { pub fn new(n: usize) -> Imosu1d { Imosu1d { n: n, dp1: vec![0;n+1], dp2: vec![0;n+1], dp3: vec![0;n+1], } } #[doc = "y=ax+b"] pub fn add_line(&mut self, l: usize, r: usize, line: ArithSeq) { if l >= r { return; } let a = line.a; let b = line.b; let y = line.y(l as i64); self.dp1[l] += y; self.dp1[r] += -y; self.dp2[l+1] += a; self.dp2[r] += -a; let L = r - (l+1); self.dp3[r] += -a * L as i64; } pub fn get(&self, k: usize) -> i64 { self.dp1[k] } fn sweep(dp: &mut [i64]) { let mut cur = 0; for i in 0..dp.len() { cur += dp[i]; dp[i] = cur; } } pub fn build(&mut self) { let n = self.dp1.len(); Self::sweep(&mut self.dp1); Self::sweep(&mut self.dp2); for i in 0..n { self.dp2[i] += self.dp3[i]; } Self::sweep(&mut self.dp2); for i in 0..n { self.dp1[i] += self.dp2[i]; } } } #[doc = "lower,upper are inclusive range"] pub struct BinarySearch<F> { pub p: F, pub lower: i64, pub upper: i64, } impl<F: FnMut(i64) -> bool> BinarySearch<F> { #[doc = "O(log(upper-lower))"] pub fn lower_bound(&mut self) -> i64 { let lower = self.lower; let upper = self.upper; assert!(lower <= upper); let mut lb = lower - 1; let mut ub = upper + 1; while ub - lb > 1 { let mid = (lb + ub) / 2; let ok = (self.p)(mid); if ok { ub = mid; } else { lb = mid; } } ub } }