結果

問題 No.26 シャッフルゲーム
ユーザー jimanojimano
提出日時 2018-01-13 15:07:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 181 ms / 5,000 ms
コード長 748 bytes
コンパイル時間 3,562 ms
コンパイル使用メモリ 80,512 KB
実行使用メモリ 41,868 KB
最終ジャッジ日時 2024-06-06 09:56:50
合計ジャッジ時間 5,825 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
41,216 KB
testcase_01 AC 137 ms
40,912 KB
testcase_02 AC 178 ms
41,712 KB
testcase_03 AC 148 ms
41,364 KB
testcase_04 AC 151 ms
40,916 KB
testcase_05 AC 160 ms
41,012 KB
testcase_06 AC 163 ms
41,660 KB
testcase_07 AC 150 ms
41,172 KB
testcase_08 AC 161 ms
41,548 KB
testcase_09 AC 181 ms
41,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package me.yukicoder.lv1;

import java.util.Scanner;

public class No0026 {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			boolean[] cup = new boolean[3];
			cup[N - 1] = true;// 最初に○印が付いているカップ

			for (int i = 0; i < M; i++) {
				int p = sc.nextInt();
				int q = sc.nextInt();
				exchange(cup, p, q);
			}

			System.out.println(cnt(cup));
		}
	}

	static void exchange(boolean[] cup, int p, int q) {
		boolean boo = cup[p - 1];
		cup[p - 1] = cup[q - 1];
		cup[q - 1] = boo;
	}

	static int cnt(boolean[] cup) {
		int cnt;
		for (cnt = 0; cnt < cup.length; cnt++) {
			if (cup[cnt])
				break;
		}
		return cnt + 1;
	}
}
0