結果

問題 No.576 E869120 and Rings
ユーザー snteasntea
提出日時 2018-05-21 16:11:00
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 4,505 bytes
コンパイル時間 3,950 ms
コンパイル使用メモリ 164,904 KB
実行使用メモリ 35,864 KB
最終ジャッジ日時 2023-09-11 00:22:15
合計ジャッジ時間 23,583 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,048 ms
34,416 KB
testcase_01 AC 1,058 ms
33,104 KB
testcase_02 AC 1,029 ms
34,324 KB
testcase_03 AC 1,071 ms
33,604 KB
testcase_04 AC 1,054 ms
33,404 KB
testcase_05 AC 1,054 ms
34,156 KB
testcase_06 AC 1,049 ms
33,820 KB
testcase_07 AC 1,054 ms
33,432 KB
testcase_08 AC 829 ms
32,748 KB
testcase_09 AC 814 ms
33,336 KB
testcase_10 AC 799 ms
33,436 KB
testcase_11 AC 812 ms
33,688 KB
testcase_12 AC 809 ms
33,964 KB
testcase_13 AC 860 ms
33,900 KB
testcase_14 AC 835 ms
35,508 KB
testcase_15 AC 605 ms
27,372 KB
testcase_16 AC 740 ms
31,544 KB
testcase_17 AC 915 ms
35,864 KB
testcase_18 AC 781 ms
31,384 KB
testcase_19 AC 786 ms
31,704 KB
testcase_20 AC 765 ms
34,152 KB
testcase_21 AC 769 ms
35,188 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused macro definition: `printf`
   --> Main.rs:126:18
    |
126 |     macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    |                  ^^^^^^
    |
    = note: `#[warn(unused_macros)]` on by default

warning: associated function `unwrap` is never used
   --> Main.rs:116:8
    |
116 |     fn unwrap(self) -> T {
    |        ^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

warning: 2 warnings emitted

ソースコード

diff #

#[allow(dead_code)]
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t:ty) => {{
        let s = getline();
        let iter = s.trim().split(' ');
        iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
    }};
}

#[allow(unused_macros)]
// macro_rules! debug {
//     ($x:expr) => {
//         println!("{}: {:?}", stringify!($x), $x)
//     };
// }
macro_rules! debug { ($x: expr) => () }

#[allow(dead_code)]
fn show<T>(iter: T) -> String
where
    T: Iterator,
    T::Item: std::fmt::Display,
{
    let mut res = iter.fold(String::new(), |sum, e| sum + &format!("{} ", e));
    res.pop();
    res
}

fn sliding_minimum<T>(a: &Vec<T>, width: usize) -> Vec<T>
where
    T: std::cmp::PartialOrd + Clone + std::fmt::Debug,
{
    let mut res = Vec::with_capacity(a.len() - width);
    let mut set = std::collections::VecDeque::new();

    for (i, e) in a.iter().enumerate().take(width) {
        while let Some((v, i)) = set.pop_back() {
            if v < e {
                set.push_back((v, i));
                break;
            }
        }
        set.push_back((e, i));
    }
    for (s, e) in a.iter().skip(width).enumerate() {
        res.push(set.front().expect("sliding_minimum error").0.clone());
        while let Some((v, i)) = set.pop_back() {
            if v < e {
                set.push_back((v, i));
                break;
            }
        }
        set.push_back((e, s + width));
        while let Some((v, i)) = set.pop_front() {
            if s + 1 <= i {
                set.push_front((v, i));
                break;
            }
        }
    }
    res.push(set.front().expect("sliding_minimum error").0.clone());

    res
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[derive(PartialEq, PartialOrd, Debug, Clone)]
struct Ordered<T: std::cmp::PartialOrd + Clone>(T);

impl<T> std::cmp::Eq for Ordered<T>
where
    T: std::cmp::PartialOrd + Clone,
{
}

impl<T> std::cmp::Ord for Ordered<T>
where
    T: std::cmp::PartialOrd + Clone,
{
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        self.partial_cmp(other).unwrap()
    }
}

impl<T: std::cmp::PartialOrd + Clone> Ordered<T> {
    fn unwrap(self) -> T {
        let Ordered(res) = self;
        res
    }
}

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    macro_rules! printf { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    macro_rules! printfln { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }

    let (n, k) = readl!(usize, usize);
    let a: Vec<i32> = readl!(String)
        .into_bytes()
        .into_iter()
        .map(|x| if x == b'0' { 0 } else { 1 })
        .collect();
    let check = |x: f64| {
        let mut a: Vec<_> = vec![0.].into_iter()
            .chain(
                a.iter().cloned()
                .chain(a.iter().cloned())
                .map(|e| e as f64 - x)
            ).collect();
        debug!(a);
        for i in 0..a.len() - 1 {
            a[i + 1] += a[i];
        }
        debug!(a);
        let maxi: Vec<_> = sliding_minimum(
            &a.iter()
                .cloned()
                .map(|x| std::cmp::Reverse(Ordered(x)))
                .collect(),
            n - k,
        ).into_iter().map(|std::cmp::Reverse(Ordered(x))| x).collect();
        debug!(maxi);
        for (&l, &rmax) in a.iter().take(n+1).zip(maxi.iter().cycle().skip(k)) { 
            if l < rmax {
                return false;
            }
        }
        true
    };
    debug!(check(1.));
    let mut l = 0.;
    let mut r = 1.;
    for _ in 0..30 {
        let m = (l + r) / 2.;
        let res = check(m);
        // debug!(res);
        if res {
            r = m;
        } else {
            l = m;
        }
    }
    printfln!("{}", r);
}
0