結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー koba-e964koba-e964
提出日時 2022-03-19 09:41:14
言語 Rust
(1.77.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,058 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 180,268 KB
実行使用メモリ 34,660 KB
最終ジャッジ日時 2024-04-14 22:35:39
合計ジャッジ時間 52,541 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,760 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 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,944 KB
testcase_08 AC 5 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 6 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 9 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 11 ms
6,944 KB
testcase_16 AC 5 ms
6,944 KB
testcase_17 AC 9 ms
6,944 KB
testcase_18 AC 149 ms
6,940 KB
testcase_19 AC 51 ms
6,944 KB
testcase_20 AC 153 ms
6,940 KB
testcase_21 AC 39 ms
6,940 KB
testcase_22 AC 61 ms
6,940 KB
testcase_23 AC 102 ms
6,944 KB
testcase_24 AC 75 ms
6,940 KB
testcase_25 AC 90 ms
6,940 KB
testcase_26 AC 121 ms
6,940 KB
testcase_27 AC 77 ms
6,940 KB
testcase_28 AC 1,043 ms
11,776 KB
testcase_29 AC 893 ms
9,472 KB
testcase_30 AC 832 ms
8,064 KB
testcase_31 AC 1,213 ms
11,392 KB
testcase_32 AC 745 ms
16,708 KB
testcase_33 AC 784 ms
8,192 KB
testcase_34 AC 1,210 ms
16,616 KB
testcase_35 AC 1,515 ms
12,288 KB
testcase_36 TLE -
testcase_37 AC 384 ms
8,064 KB
testcase_38 AC 1,187 ms
9,472 KB
testcase_39 AC 681 ms
7,040 KB
testcase_40 AC 851 ms
9,344 KB
testcase_41 AC 1,059 ms
12,672 KB
testcase_42 TLE -
testcase_43 AC 1,085 ms
11,392 KB
testcase_44 AC 1,598 ms
12,928 KB
testcase_45 AC 1,335 ms
12,092 KB
testcase_46 AC 1,225 ms
15,872 KB
testcase_47 AC 564 ms
8,448 KB
testcase_48 TLE -
testcase_49 TLE -
testcase_50 TLE -
testcase_51 TLE -
testcase_52 TLE -
testcase_53 TLE -
testcase_54 TLE -
testcase_55 TLE -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 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 ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

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 snd_light: Vec<_> = snd.iter().map(|&(a, b, _)| (a, b)).collect();
    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_light.binary_search(&(quo(mid, f), INF)).unwrap_err();
                count += idx as i64;
            } else {
                let idx = snd_light.binary_search(&(quo(-mid - f - 1, -f), -INF)).unwrap_err();
                count += (snd.len() - idx) as i64;
            }
        }
        if count >= s {
            pass = mid;
        } else {
            fail = mid;
        }
    }
    println!("{}", pass);
    for &(f, f1, f2) in &fst {
        if f == 0 {
            if pass != 0 {
                continue;
            }
            let (_, s1, s2) = snd[0];
            println!("{} {} {} {}",  f1, f2, s1, s2);
            return;
        }
        if pass % f != 0 {
            continue;
        }
        let q = pass / f;
        let lo = snd.binary_search(&(q, -INF, -INF)).unwrap_err();
        if lo < snd.len() {
            let (q2, s1, s2) = snd[lo];
            if q2 == q {
                println!("{} {} {} {}", f1, f2, s1, s2);
                return;
            }
        }
    }
}
0