結果

問題 No.602 隠されていたゲーム2
ユーザー take4s5itake4s5i
提出日時 2021-12-01 11:35:27
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 2,232 bytes
コンパイル時間 3,835 ms
コンパイル使用メモリ 159,484 KB
実行使用メモリ 5,660 KB
最終ジャッジ日時 2023-09-17 15:56:52
合計ジャッジ時間 9,674 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 655 ms
4,376 KB
testcase_17 AC 38 ms
4,376 KB
testcase_18 AC 1,494 ms
4,852 KB
testcase_19 AC 17 ms
5,660 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: field `move_len` is never read
 --> Main.rs:7:5
  |
6 | struct Input {
  |        ----- field in this struct
7 |     move_len: usize,
  |     ^^^^^^^^
  |
  = note: `Input` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::collections::BTreeSet;
use std::io;
use std::ops::Bound;

#[derive(Debug, Clone)]
struct Input {
    move_len: usize,
    moves: BTreeSet<usize>,
    dest: (i64, i64),
    mt_len: usize,
}

impl Input {
    fn search_dest(&self) -> isize {
        if self.dest == (0, 0) {
            0
        } else if self.moves.contains(&self.mt_len) {
            1
        } else if self.search_dest_with_2_moves() {
            2
        } else {
            -1
        }
    }

    fn search_dest_with_2_moves(&self) -> bool {
        // 足して行けるパターン
        for i in self
            .moves
            .range((Bound::Unbounded, Bound::Excluded(self.mt_len)))
        {
            for j in self.moves.range((
                Bound::Included(self.mt_len - i),
                Bound::Excluded(self.mt_len),
            )) {
                if (i + j) == self.mt_len {
                    return true;
                }
            }
        }

        // 引いて行けるパターン
        for i in self
            .moves
            .range((Bound::Excluded(self.mt_len), Bound::Unbounded))
        {
            for j in self
                .moves
                .range((Bound::Unbounded, Bound::Included(i - self.mt_len)))
            {
                if (i - j) == self.mt_len {
                    return true;
                }
            }
        }

        false
    }
}

fn get_input() -> Input {
    let mut buf = String::new();

    io::stdin().read_line(&mut buf).unwrap();
    let move_len: usize = buf.clone().trim().parse().unwrap();
    buf.clear();

    io::stdin().read_line(&mut buf).unwrap();
    let moves: BTreeSet<usize> = buf
        .clone()
        .trim()
        .splitn(move_len, ' ')
        .map(|s: &str| s.parse().unwrap())
        .collect();
    buf.clear();

    io::stdin().read_line(&mut buf).unwrap();
    let dest: Vec<i64> = buf
        .trim()
        .splitn(2, ' ')
        .map(|s: &str| s.parse().unwrap())
        .collect();

    Input {
        move_len,
        moves,
        dest: (dest[0], dest[1]),
        mt_len: (dest[0].abs() + dest[1].abs()) as usize,
    }
}

fn main() {
    let input = get_input();
    println!("{}", input.search_dest());
}
0