Submission #1430642


Source Code Expand

Copy
use std::io;
use std::io::prelude::*;

fn ask(n: String) -> bool {
    let mut stdout = io::stdout();
    stdout.write(format!("? {}\n", n).as_bytes());
    stdout.flush();
    let mut stdin = io::stdin();
    let mut input = String::new();
    stdin.read_line(&mut input);
    input.starts_with("Y")
}

fn is_last(s: &str) -> bool {
    if s.starts_with("1") || (s.len() == 0 && ask("1000000000000".to_string())) {
        let mut t = String::new();
        for _ in 0..s.len()+1 {
            t += "9";
        }
        ask(t)
    } else {
        let mut t = String::new();
        t += "1";
        for _ in 0..s.len()+1 {
            t += "0";
        }
        !ask(t)
    }
}
fn find_last(s: &str) -> i32 {
    let mut lb = if s.len() == 0 { 1 } else { 0 } - 1;
    let mut ub = 9;
    while ub - lb > 1 {
        let x = (lb + ub) / 2;
        if ask(s.to_string() + &x.to_string() + "0") {
            ub = x;
        } else {
            lb = x;
        }
    }
    ub
}
fn find_char(s: &str) -> (i32, bool) {
    let mut lb = 0;
    let mut ub = 10;
    // [lb, ub)
    while ub - lb > 1 {
        let x = (lb + ub) / 2;
        if ask(s.to_string() + &x.to_string()) {
            lb = x;
        } else {
            ub = x;
        }
    }
    if lb != 9 {
        (lb, false)
    } else if is_last(s) {
        (find_last(s), true)
    } else {
        (9, false)
    }
}
fn main() {
    let mut ans = String::new();
    loop {
        let (a, b) = find_char(&ans);
        ans += &a.to_string();
        if b {
            break;
        }
    }

    let mut stdout = io::stdout();
    stdout.write(format!("! {}\n", ans).as_bytes());
    stdout.flush();
}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashSet;

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n { vs.push(readln()); }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);

Submission Info

Submission Time
Task E - Awkward Response
User ichyo
Language Rust (1.15.1)
Score 800
Code Size 3311 Byte
Status AC
Exec Time 5 ms
Memory 4692 KB

Compile Error

warning: unused result which must be used, #[warn(unused_must_use)] on by default
 --> ./Main.rs:6:5
  |
6 |     stdout.write(format!("? {}\n", n).as_bytes());
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: unused result which must be used, #[warn(unused_must_use)] on by default
 --> ./Main.rs:7:5
  |
7 |     stdout.flush();
  |     ^^^^^^^^^^^^^^^

warning: variable does not need to be mutable, #[warn(unused_mut)] on by default
 --> ./Main.rs:8:9
  |
8 |     let mut stdin = io::stdin();
  |         ^^^^^^^^^

warning: unused result which must be used, #[warn(unused_must_use)] on by default
  --> ./Main.rs:10:5
   |
10 |     stdin.read_line(&mut input);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: unused result which must be used, #[warn(unused_must_use)] on by default
  --> ./Main.rs:74:5
   |
74 |     stdout.write(format!("! {}\n", ans).as_bytes());
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: unused result which must be used, #[warn(unused_must_use)] on by d...

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 1
AC × 40
Set Name Test Cases
Sample 00_example_01.txt
All 00_example_01.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 4 ms 4688 KB
01.txt AC 4 ms 4688 KB
02.txt AC 4 ms 4684 KB
03.txt AC 4 ms 4688 KB
04.txt AC 4 ms 4688 KB
05.txt AC 5 ms 4688 KB
06.txt AC 5 ms 4684 KB
07.txt AC 5 ms 4688 KB
08.txt AC 5 ms 4688 KB
09.txt AC 4 ms 4688 KB
10.txt AC 4 ms 4688 KB
11.txt AC 4 ms 4692 KB
12.txt AC 4 ms 4684 KB
13.txt AC 4 ms 4692 KB
14.txt AC 5 ms 4684 KB
15.txt AC 5 ms 4688 KB
16.txt AC 5 ms 4688 KB
17.txt AC 5 ms 4688 KB
18.txt AC 4 ms 4684 KB
19.txt AC 4 ms 4688 KB
20.txt AC 4 ms 4688 KB
21.txt AC 4 ms 4692 KB
22.txt AC 4 ms 4684 KB
23.txt AC 4 ms 4684 KB
24.txt AC 4 ms 4692 KB
25.txt AC 4 ms 4688 KB
26.txt AC 4 ms 4684 KB
27.txt AC 5 ms 4692 KB
28.txt AC 5 ms 4688 KB
29.txt AC 5 ms 4688 KB
30.txt AC 5 ms 4684 KB
31.txt AC 4 ms 4692 KB
32.txt AC 4 ms 4692 KB
33.txt AC 4 ms 4684 KB
34.txt AC 4 ms 4692 KB
35.txt AC 5 ms 4688 KB
36.txt AC 5 ms 4692 KB
37.txt AC 5 ms 4692 KB
38.txt AC 5 ms 4688 KB
39.txt AC 5 ms 4692 KB