結果

問題 No.123 カードシャッフル
ユーザー spacia
提出日時 2016-01-04 09:36:02
言語 Java
(openjdk 23)
結果
AC  
実行時間 177 ms / 5,000 ms
コード長 986 bytes
コンパイル時間 1,928 ms
コンパイル使用メモリ 78,012 KB
実行使用メモリ 60,836 KB
最終ジャッジ日時 2024-09-19 11:07:55
合計ジャッジ時間 3,747 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.math.*;

class Main {
	
	public static void out (Object o) {
		System.out.println(o);
	}
	
	public static int[] init (int n) {
		int[] ret = new int[n];
		for (int i = 0; i < n; i++) {
			ret[i] = i + 1;
		}
		return ret;
	}
	
	public static int[] shuffle (int[] nums , int s) {
		int tmp = nums[s];
		for (int i = s; i > 0; i--) {
			nums[i] = nums[i - 1];
		}
		nums[0] = tmp;
		return nums;
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		String[] line1 = br.readLine().split(" ");
		String[] line2 = br.readLine().split(" ");
		int n = Integer.parseInt(line1[0]);
		int m = Integer.parseInt(line1[1]);
		int[] nums = init(n);
		
		//out(Arrays.toString(nums));
		
		for (int i = 0; i < m; i++) {
			int s = Integer.parseInt(line2[i]);
			nums = shuffle(nums , s - 1);
			//out(Arrays.toString(nums));
		}
		
		out(nums[0]);
	}
}
0