結果

問題 No.26 シャッフルゲーム
ユーザー eagleeagle
提出日時 2022-06-20 10:38:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 179 ms / 5,000 ms
コード長 843 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 74,200 KB
実行使用メモリ 42,060 KB
最終ジャッジ日時 2024-04-20 23:01:20
合計ジャッジ時間 4,533 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
41,148 KB
testcase_01 AC 135 ms
41,384 KB
testcase_02 AC 179 ms
41,852 KB
testcase_03 AC 146 ms
41,568 KB
testcase_04 AC 146 ms
41,520 KB
testcase_05 AC 160 ms
41,640 KB
testcase_06 AC 153 ms
41,652 KB
testcase_07 AC 164 ms
41,548 KB
testcase_08 AC 166 ms
41,916 KB
testcase_09 AC 172 ms
42,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//〇印がついているカップの位置番号
		int N = sc.nextInt();
		//カップを入れ替える回数
		int M = sc.nextInt();
		//カップ
		int[] cup = new int[3];
		//カップに〇をつける
		cup[N-1] = 1;
		//M回カップを入れ替える
		for(int i = 0; i < M; i++) {
			//入れ替えるカップ
			int c1 = sc.nextInt();
			int c2 = sc.nextInt();
			//カップの入れ替え作業
			int c = cup[c1-1];
			cup[c1-1] = cup[c2-1];
			cup[c2-1] = c;
		}
		//〇印がついているカップを探す
		int ans = -1;
		for(int i = 0; i < cup.length; i++) {
			if(cup[i] == 1) {
				ans = i + 1;
			}
		}
		System.out.println(ans);
	}
}
0