結果
| 問題 | 
                            No.1312 Snake Eyes
                             | 
                    
| コンテスト | |
| ユーザー | 
                             fukafukatani
                         | 
                    
| 提出日時 | 2020-12-13 10:44:12 | 
| 言語 | Rust  (1.83.0 + proconio)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,755 bytes | 
| コンパイル時間 | 12,621 ms | 
| コンパイル使用メモリ | 386,772 KB | 
| 実行使用メモリ | 10,624 KB | 
| 最終ジャッジ日時 | 2024-09-19 23:25:26 | 
| 合計ジャッジ時間 | 34,299 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 45 TLE * 1 -- * 39 | 
コンパイルメッセージ
warning: function `read_vec` is never used
   --> src/main.rs:112:4
    |
112 | fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    |    ^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default
            
            ソースコード
#![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 + 1 {
                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 == 1 && i == 3 {
                debug!(ng);
                debug!(criterion(1));
                debug!(criterion(2));
            }
            */
            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()
}
            
            
            
        
            
fukafukatani