結果

問題 No.1312 Snake Eyes
ユーザー fukafukatanifukafukatani
提出日時 2020-12-13 00:58:20
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,751 bytes
コンパイル時間 826 ms
コンパイル使用メモリ 180,496 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-20 02:53:15
合計ジャッジ時間 22,634 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 328 ms
4,348 KB
testcase_24 AC 380 ms
4,348 KB
testcase_25 AC 216 ms
4,348 KB
testcase_26 AC 151 ms
4,348 KB
testcase_27 AC 352 ms
4,348 KB
testcase_28 AC 204 ms
4,348 KB
testcase_29 AC 630 ms
4,348 KB
testcase_30 AC 286 ms
4,348 KB
testcase_31 AC 469 ms
4,348 KB
testcase_32 AC 493 ms
4,348 KB
testcase_33 AC 64 ms
4,348 KB
testcase_34 AC 599 ms
4,348 KB
testcase_35 AC 460 ms
4,348 KB
testcase_36 AC 581 ms
4,348 KB
testcase_37 AC 649 ms
4,348 KB
testcase_38 AC 1,074 ms
4,348 KB
testcase_39 AC 1,211 ms
4,348 KB
testcase_40 AC 1,213 ms
4,348 KB
testcase_41 AC 1,204 ms
4,348 KB
testcase_42 AC 1,027 ms
4,348 KB
testcase_43 AC 1,208 ms
4,348 KB
testcase_44 AC 1,070 ms
4,348 KB
testcase_45 AC 1,156 ms
4,348 KB
testcase_46 AC 1,202 ms
4,348 KB
testcase_47 AC 1,115 ms
4,348 KB
testcase_48 TLE -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
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 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: function `read_vec` is never used
   --> Main.rs:112:4
    |
112 | fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    |    ^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<i64>();
    let mut ans = n + 1;

    // debug!(with_p(2, 2));
    for di in 1i64..1000001 {
        for i in 1.. {
            if (di + 1).pow(i) > n {
                break;
            }

            let criterion = |mid: i64| -> bool {
                if mid == 1 {
                    return true;
                }
                if mid == n + 1 {
                    return false;
                }
                let v = with_p(n, mid);
                if v.len() != i as usize {
                    return v.len() > i as usize;
                }
                for num in v {
                    if num < di {
                        return false;
                    }
                    if num > di {
                        return true;
                    }
                }
                false
            };

            let (_, ng) = binary_search(1, n + 1, criterion);
            /*
            if di == 3 && i == 3 {
                debug!(ng);
                debug!(criterion(5));
                debug!(criterion(6));
            }
            */

            let criterion2 = |mid: i64| -> bool {
                let v = with_p(n, mid);
                if v.len() != i as usize {
                    return false;
                }
                return v.iter().all(|&e| e == di);
            };
            if criterion2(ng) && ng < ans {
                ans = ng;
            }
        }
    }

    println!("{}", ans);
}

type Input = i64;
fn binary_search<F>(lb: Input, ub: Input, criterion: F) -> (Input, Input)
where
    F: Fn(Input) -> bool,
{
    assert_eq!(criterion(lb), true);
    assert_eq!(criterion(ub), false);
    let mut ok = lb;
    let mut ng = ub;
    while ng - ok > 1 {
        let mid = (ng + ok) / 2;
        if criterion(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    (ok, ng)
}

fn with_p(mut n: i64, p: i64) -> Vec<i64> {
    let mut v = vec![];
    while n > 0 {
        v.push(n % p);
        n /= p;
    }
    v.reverse();
    v
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0