結果
| 問題 |
No.365 ジェンガソート
|
| コンテスト | |
| ユーザー |
spacia
|
| 提出日時 | 2016-06-03 11:06:08 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 985 bytes |
| コンパイル時間 | 2,007 ms |
| コンパイル使用メモリ | 76,880 KB |
| 実行使用メモリ | 78,472 KB |
| 最終ジャッジ日時 | 2024-10-08 06:12:45 |
| 合計ジャッジ時間 | 21,026 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 38 TLE * 2 -- * 1 |
ソースコード
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(Arrays.toString(nums));
//System.out.println(Arrays.toString(pos));
System.out.println(solve(nums, pos));
sc.close();
}
public static int solve (int[] nums, int[] pos) {
int lim = nums.length;
for (int i = 0; i < lim; i++) {
if (isSorted(nums)) {
return i;
} else {
int p = pos[i + 1];
nums[p] = -1;
}
}
return -1;
}
public static boolean isSorted (int[] nums) {
int head = -1;
for (int i = 0; i < nums.length; i++) {
if (nums[i] == -1) continue;
if (head == -1) {
head = nums[i];
continue;
} else if (head > nums[i]) {
return false;
} else {
head = nums[i];
}
}
return true;
}
}
spacia