結果
| 問題 |
No.26 シャッフルゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-02 10:20:45 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 2,414 bytes |
| コンパイル時間 | 12,636 ms |
| コンパイル使用メモリ | 389,144 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 18:36:53 |
| 合計ジャッジ時間 | 13,541 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
コンパイルメッセージ
warning: field `shuffle_count` is never read
--> src/main.rs:15:5
|
11 | struct InputData {
| --------- field in this struct
...
15 | shuffle_count: i32,
| ^^^^^^^^^^^^^
|
= note: `InputData` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
= note: `#[warn(dead_code)]` on by default
ソースコード
//! No.26 シャッフルゲーム
//! https://yukicoder.me/problems/no/26
use std::io;
#[cfg(test)]
mod test;
/// 入力データ
#[derive(Debug)]
struct InputData {
/// 最初に○印が付いているカップの位置
first_position: i32,
/// シャッフル回数
shuffle_count: i32,
/// シャッフルした位置
shuffle_indices: Vec<[i32; 2]>,
}
/// エントリポイント
fn main() {
let input = input_data();
println!("{}", position_number(input));
}
/// ○印がついているカップの位置を返します。
fn position_number(input: InputData) -> i32 {
// カップの位置情報(true:○、false:×)
let mut correct_answer: [bool; 3] = [false, false, false];
// 初期値
correct_answer[(input.first_position - 1) as usize] = true;
for index in input.shuffle_indices {
let i = (index[0] - 1) as usize;
let j = (index[1] - 1) as usize;
let temp = correct_answer[i];
correct_answer[i] = correct_answer[j];
correct_answer[j] = temp;
// 配列のswapは&mutでムーブされてしまうため、エラーが発生する。
// error[E0499]: cannot borrow `correct_answer[..]` as mutable more than once at a time
// std::mem::swap(&mut correct_answer[i], &mut correct_answer[j]);
}
// 結果を探す
for (i, ans) in correct_answer.iter().enumerate() {
if *ans {
return i as i32 + 1i32;
}
}
// ここには来ない
0
}
/// 標準入力から文字列を取得します。
fn input_data() -> InputData {
// 1行目
let mut s1 = String::new();
io::stdin().read_line(&mut s1).unwrap();
let first_position: i32 = s1.trim().parse().unwrap();
// 2行目
let mut s2 = String::new();
io::stdin().read_line(&mut s2).unwrap();
let shuffle_count: i32 = s2.trim().parse().unwrap();
// 3行目以降
let mut shuffle_indices = Vec::new();
for _i in 0..shuffle_count {
let mut s3 = String::new();
io::stdin().read_line(&mut s3).unwrap();
let sp: Vec<&str> = s3.trim().split_whitespace().collect();
let array: [i32; 2] = [
sp[0].parse().unwrap(),
sp[1].parse().unwrap(),
];
shuffle_indices.push(array);
}
InputData {
first_position,
shuffle_count,
shuffle_indices,
}
}