結果

問題 No.26 シャッフルゲーム
ユーザー tokustokus
提出日時 2021-11-17 22:24:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 70 ms / 5,000 ms
コード長 1,601 bytes
コンパイル時間 4,096 ms
コンパイル使用メモリ 79,484 KB
実行使用メモリ 51,456 KB
最終ジャッジ日時 2023-08-25 19:10:35
合計ジャッジ時間 4,885 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
50,496 KB
testcase_01 AC 55 ms
50,572 KB
testcase_02 AC 69 ms
51,432 KB
testcase_03 AC 59 ms
50,416 KB
testcase_04 AC 63 ms
50,852 KB
testcase_05 AC 66 ms
50,576 KB
testcase_06 AC 66 ms
50,648 KB
testcase_07 AC 61 ms
50,672 KB
testcase_08 AC 67 ms
50,664 KB
testcase_09 AC 70 ms
51,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.stream.Stream;

class Main {
    public static void main(String[] args) {
        no26();
    }
    
    // No.26 シャッフルゲーム
    private static void no26() {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        // カップの位置
        int correct;
        // 回数
        int turn;
        // 入れ替え位置
        int[][] replacement;

        try {
            String co = reader.readLine();
            correct = Integer.parseInt(co);

            String tn = reader.readLine();
            turn = Integer.parseInt(tn);

            replacement = new int[turn][];

            for (int i = 0; i < turn; i++) {
                String line = reader.readLine();
                replacement[i] = Stream.of(line.split(" ")).mapToInt(Integer::parseInt).toArray();
            }
            reader.close();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }

        String[] cups = new String[3];

        cups[correct - 1] = String.valueOf(correct);

        for (int i = 0; i < replacement.length; i++) {
            String cup = cups[replacement[i][0] - 1];
            cups[replacement[i][0] - 1] = cups[replacement[i][1] - 1];
            cups[replacement[i][1] - 1] = cup;
        }

        for (int i = 0; i < cups.length; i++) {
            if (cups[i] != null) {
                System.out.println(i + 1);
            }
        }
    }
}

0