結果

問題 No.123 カードシャッフル
ユーザー Ryota EnokidoRyota Enokido
提出日時 2018-12-11 09:55:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 526 ms / 5,000 ms
コード長 821 bytes
コンパイル時間 3,165 ms
コンパイル使用メモリ 74,504 KB
実行使用メモリ 62,736 KB
最終ジャッジ日時 2023-10-19 22:21:21
合計ジャッジ時間 7,510 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,600 KB
testcase_01 AC 136 ms
57,176 KB
testcase_02 AC 139 ms
57,496 KB
testcase_03 AC 138 ms
57,488 KB
testcase_04 AC 137 ms
55,716 KB
testcase_05 AC 137 ms
57,548 KB
testcase_06 AC 139 ms
57,496 KB
testcase_07 AC 140 ms
57,460 KB
testcase_08 AC 139 ms
57,736 KB
testcase_09 AC 138 ms
57,300 KB
testcase_10 AC 488 ms
61,924 KB
testcase_11 AC 526 ms
62,636 KB
testcase_12 AC 507 ms
62,736 KB
testcase_13 AC 522 ms
62,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
  
  public class Main {
      public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          
          int N = sc.nextInt();
          int M = sc.nextInt();
          int Card[] = new int[N];
          
          //カード配列作成
          for(int i=0; i<N; i++){
              Card[i] = i+1;
          }
          
          // シャッフル
          for(int j=0; j<M; j++){
              //K番目を1番目に
              int K = sc.nextInt();
              int temp = Card[K-1];
              
              //カードを後ろにずらす
              while (K-1>0){
                  Card[K-1] = Card[K-2];
                  K--;
              }
              Card[0]=temp;
          }
          System.out.println(Card[0]);
      }
  }
0