結果
| 問題 |
No.1312 Snake Eyes
|
| コンテスト | |
| ユーザー |
fukafukatani
|
| 提出日時 | 2020-12-13 00:58:20 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,751 bytes |
| コンパイル時間 | 11,160 ms |
| コンパイル使用メモリ | 392,292 KB |
| 実行使用メモリ | 13,756 KB |
| 最終ジャッジ日時 | 2024-09-19 22:39:39 |
| 合計ジャッジ時間 | 30,990 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 WA * 3 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 {
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()
}
fukafukatani