結果

問題 No.123 カードシャッフル
ユーザー r.suzukir.suzuki
提出日時 2016-01-03 22:28:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 536 ms / 5,000 ms
コード長 651 bytes
コンパイル時間 3,657 ms
コンパイル使用メモリ 74,820 KB
実行使用メモリ 64,372 KB
最終ジャッジ日時 2023-10-19 14:49:39
合計ジャッジ時間 7,820 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
57,336 KB
testcase_01 AC 131 ms
57,592 KB
testcase_02 AC 133 ms
57,476 KB
testcase_03 AC 132 ms
57,276 KB
testcase_04 AC 136 ms
57,456 KB
testcase_05 AC 135 ms
57,480 KB
testcase_06 AC 131 ms
57,480 KB
testcase_07 AC 132 ms
57,548 KB
testcase_08 AC 134 ms
57,424 KB
testcase_09 AC 134 ms
57,512 KB
testcase_10 AC 496 ms
61,964 KB
testcase_11 AC 536 ms
64,372 KB
testcase_12 AC 507 ms
62,092 KB
testcase_13 AC 518 ms
62,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

public class No_123 {

	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int n = sc.nextInt();
		int card[] = new int[n];

		for (int i = 1; i <= n; i++) {
			card[i - 1] = i;
		}

		int m = sc.nextInt();
		int[] shuffle = new int[m];
		for (int i = 0; i < m; i++) {
			shuffle[i] = sc.nextInt();
		}

		for (int s : shuffle) {
			int tmp = card[s - 1];// 抜くカードを確保
			for (int i = s - 1; i > 0; i--) {
				card[i] = card[i - 1];// 後ろにコピーしてゆく
			}
			card[0] = tmp;// 抜いたカードを一番上に積む
		}
		System.out.println(card[0]);
		sc.close();

	}

}
0