結果

問題 No.360 増加門松列
ユーザー tubo28tubo28
提出日時 2016-04-17 23:09:02
言語 Rust
(1.72.1)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,427 bytes
コンパイル時間 3,834 ms
コンパイル使用メモリ 110,720 KB
最終ジャッジ日時 2023-08-25 18:35:23
合計ジャッジ時間 4,183 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
error: use of deprecated `try` macro
  --> Main.rs:61:17
   |
61 |         let s = try!(self.fetch_token());
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated
help: you can use the `?` operator instead
   |
61 -         let s = try!(self.fetch_token());
61 +         let s = self.fetch_token()?;
   |
help: alternatively, you can still access the deprecated `try!()` macro using the "raw identifier" syntax
   |
61 |         let s = r#try!(self.fetch_token());
   |                 ++

error: use of deprecated `try` macro
  --> Main.rs:62:17
   |
62 |         let t = try!(s.parse::<T>().map_err(|_| "Parse error"));
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated
help: you can use the `?` operator instead
   |
62 -         let t = try!(s.parse::<T>().map_err(|_| "Parse error"));
62 +         let t = s.parse::<T>().map_err(|_| "Parse error")?;
   |
help: alternatively, you can still access the deprecated `try!()` macro using the "raw identifier" syntax
   |
62 |         let t = r#try!(s.parse::<T>().map_err(|_| "Parse error"));
   |                 ++

error: aborting due to 2 previous errors

ソースコード

diff #

fn main(){
    let mut sc = Scanner::new();
    while let Ok(x) = sc.wrapped() {
        let mut a = vec![0; 7];
        a[0] = x;
        for i in 1..7 { a[i] = sc.next(); }
        let mut used = vec![false; 7];
        let mut tmp = vec![];
        let p = dfs(&mut tmp, &mut used, &a);
        println!("{}", if p { "YES" } else { "NO" });
    }

    fn dfs(cur: &mut Vec<i32>, used: &mut Vec<bool>, a: &Vec<i32>) -> bool {
        if cur.len() == 7 {
            is_kdmt_7(cur)
        } else {
            for i in 0..7 {
                if !used[i] {
                    used[i] = true;
                    cur.push(a[i]);
                    if dfs(cur, used, a) { return true; }
                    cur.pop();
                    used[i] = false;
                }
            };
            false
        }
    }
    
}

fn is_kdmt(x: i32, y: i32, z: i32) -> bool {
    return x != y && y != z && z != x &&
        ((y < x && y < z) || (y > x && y > z)) && x < z;
}

fn is_kdmt_7(x: &mut Vec<i32>) -> bool {
    for i in 0..5 {
        if !is_kdmt(x[i], x[i+1], x[i+2]) {
            return false;
        }
    }
    return true;
}

// Scanner

#[allow(dead_code)]
struct Scanner {
    token_buffer : Vec<String>,
    index : usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner{
        Scanner { token_buffer: vec![], index: 0 }
    }

    fn wrapped<T>(& mut self) -> Result<T,&str> where T: std::str::FromStr {
        let s = try!(self.fetch_token());
        let t = try!(s.parse::<T>().map_err(|_| "Parse error"));
        Ok(t)
    }
    fn next<T>(& mut self) -> T where T: std::str::FromStr {
        self.wrapped::<T>().unwrap()
    }
    fn ni(& mut self) -> i32 {
        self.next::<i32>()
    }

    fn fetch_token(&mut self) -> Result<&String,&str> {
        while self.index >= self.token_buffer.len() {
            let mut st = String::new();
            while st.trim() == "" {
                match std::io::stdin().read_line(&mut st) {
                    Ok(l) if l > 0 => continue,
                    Ok(_)  => return Err("End of file"),
                    Err(_) => return Err("Failed to read line"),
                }
            }
            self.token_buffer = st.split_whitespace()
                .map(|x| x.to_string())
                .collect();
            self.index = 0;
        }

        self.index += 1;
        Ok(&self.token_buffer[self.index - 1])
    }
}
0