結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー koba-e964koba-e964
提出日時 2021-10-21 13:32:33
言語 Rust
(1.77.0 + proconio)
結果
RE  
実行時間 -
コード長 3,888 bytes
コンパイル時間 14,868 ms
コンパイル使用メモリ 378,808 KB
実行使用メモリ 22,760 KB
最終ジャッジ日時 2024-09-21 08:56:04
合計ジャッジ時間 57,579 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 6 ms
5,376 KB
testcase_18 AC 92 ms
5,376 KB
testcase_19 AC 35 ms
5,376 KB
testcase_20 AC 99 ms
5,376 KB
testcase_21 AC 23 ms
5,376 KB
testcase_22 AC 40 ms
5,376 KB
testcase_23 AC 64 ms
5,376 KB
testcase_24 AC 51 ms
5,376 KB
testcase_25 AC 62 ms
5,376 KB
testcase_26 AC 78 ms
5,376 KB
testcase_27 AC 51 ms
5,376 KB
testcase_28 RE -
testcase_29 AC 561 ms
7,424 KB
testcase_30 AC 535 ms
6,784 KB
testcase_31 AC 706 ms
9,472 KB
testcase_32 AC 456 ms
11,648 KB
testcase_33 AC 499 ms
6,912 KB
testcase_34 AC 684 ms
11,392 KB
testcase_35 AC 920 ms
10,240 KB
testcase_36 AC 1,290 ms
15,304 KB
testcase_37 AC 241 ms
6,144 KB
testcase_38 AC 730 ms
8,192 KB
testcase_39 AC 426 ms
6,016 KB
testcase_40 AC 520 ms
7,424 KB
testcase_41 AC 662 ms
9,728 KB
testcase_42 AC 1,320 ms
13,056 KB
testcase_43 AC 674 ms
8,960 KB
testcase_44 AC 988 ms
10,624 KB
testcase_45 AC 894 ms
8,960 KB
testcase_46 AC 678 ms
12,032 KB
testcase_47 AC 370 ms
6,944 KB
testcase_48 AC 1,543 ms
22,464 KB
testcase_49 AC 1,299 ms
19,936 KB
testcase_50 AC 1,626 ms
19,304 KB
testcase_51 AC 1,443 ms
21,584 KB
testcase_52 AC 1,331 ms
19,096 KB
testcase_53 AC 1,884 ms
21,284 KB
testcase_54 AC 1,833 ms
19,180 KB
testcase_55 TLE -
testcase_56 AC 1,858 ms
22,760 KB
testcase_57 AC 1,430 ms
19,840 KB
testcase_58 AC 1,233 ms
19,612 KB
testcase_59 AC 1,227 ms
21,988 KB
testcase_60 AC 1,212 ms
20,224 KB
testcase_61 AC 1,188 ms
19,180 KB
testcase_62 AC 1,184 ms
18,856 KB
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 AC 1 ms
6,948 KB
testcase_71 AC 1 ms
6,940 KB
testcase_72 AC 1 ms
6,940 KB
testcase_73 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_imports)]
use std::cmp::*;
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

trait Bisect<T> {
    fn lower_bound(&self, val: &T) -> usize;
    fn upper_bound(&self, val: &T) -> usize;
}

impl<T: Ord> Bisect<T> for [T] {
    fn lower_bound(&self, val: &T) -> usize {
        let mut pass = self.len() + 1;
        let mut fail = 0;
        while pass - fail > 1 {
            let mid = (pass + fail) / 2;
            if &self[mid - 1] >= val {
                pass = mid;
            } else {
                fail = mid;
            }
        }
        pass - 1
    }
    fn upper_bound(&self, val: &T) -> usize {
        let mut pass = self.len() + 1;
        let mut fail = 0;
        while pass - fail > 1 {
            let mid = (pass + fail) / 2;
            if &self[mid - 1] > val {
                pass = mid;
            } else {
                fail = mid;
            }
        }
        pass - 1
    }
}

fn two(a: &[i64], b: &[i64]) -> Vec<(i64, i64, i64)> {
    let mut ans = vec![];
    for &a in a {
        for &b in b {
            ans.push((a * b, a, b));
        }
    }
    ans.sort_unstable();
    ans
}

fn quo(a: i64, b: i64) -> i64 {
    assert!(b > 0);
    let mut r = a % b;
    if r < 0 {
        r += b;
    }
    (a - r) / b
}

const INF: i64 = 1 << 60;

fn main() {
    input! {
        k: usize, l: usize, m: usize, n: usize, s: i64,
        a: [i64; k],
        b: [i64; l],
        c: [i64; m],
        d: [i64; n],
    }
    let fst = two(&a, &b);
    let snd = two(&c, &d);
    let mut pass = INF;
    let mut fail = -INF;
    while pass - fail > 1 {
        let mid = fail + (pass - fail) / 2;
        let mut count = 0;
        for &(f, _, _) in &fst {
            if f == 0 {
                if mid >= 0 {
                    count += snd.len() as i64;
                }
            } else if f > 0 {
                let idx = snd.upper_bound(&(quo(mid, f), INF, INF));
                count += idx as i64;
            } else {
                let idx = snd.lower_bound(&(quo(-mid - f - 1, -f), -INF, -INF));
                count += (snd.len() - idx) as i64;
            }
        }
        if count >= s {
            pass = mid;
        } else {
            fail = mid;
        }
    }
    println!("{}", pass);
    for &(f, f1, f2) in &fst {
        if pass % f != 0 {
            continue;
        }
        let q = pass / f;
        let lo = snd.lower_bound(&(q, -INF, -INF));
        let hi = snd.upper_bound(&(q, INF, INF));
        if lo < hi {
            let (_, s1, s2) = snd[lo];
            println!("{} {} {} {}", f1, f2, s1, s2);
            return;
        }
    }
}
0