結果

問題 No.365 ジェンガソート
ユーザー spacia
提出日時 2016-06-03 11:25:36
言語 Java
(openjdk 23)
結果
AC  
実行時間 656 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 2,298 ms
コンパイル使用メモリ 78,596 KB
実行使用メモリ 49,208 KB
最終ジャッジ日時 2024-10-12 02:21:27
合計ジャッジ時間 18,095 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

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[] nums = new int[n];
		int[] pos  = new int[n + 1];

		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
			pos[nums[i]] = i;
		}

		System.out.println(solve(nums, pos));

		sc.close();
	}

	public static int solve (int[] nums, int[] pos) {
		for (int i = nums.length; i > 1; i--)
			if (pos[i] < pos[i - 1]) return i - 1;
		return 0;
	}

}
0