結果

問題 No.365 ジェンガソート
ユーザー keitamido
提出日時 2017-06-10 15:44:32
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 698 bytes
コンパイル時間 2,874 ms
コンパイル使用メモリ 76,332 KB
実行使用メモリ 76,620 KB
最終ジャッジ日時 2024-09-24 15:41:54
合計ジャッジ時間 9,969 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 TLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class JengaSortFix2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int max = sc.nextInt();
		int cnt = max - 1;
		ArrayList<Integer> nlist = new ArrayList<Integer>();
		nlist.add(sc.nextInt());
		for (int i = 0; i < max - 1; i++) {
			int next = sc.nextInt();
			if (next > JengaSortFix2.maxNum(nlist)) {
				if (nlist.contains(next - 1)) {
					cnt--;
				} else {
					cnt = max - 1;
				}
			nlist.add(next);
			}
		}
		System.out.println(cnt);
	}
	private static int maxNum(ArrayList<Integer> nlist) {
		int max = 0;
		for (Integer n : nlist) {
			int num = n.intValue();
			if (num > max) {
				max = num;
			}
		}
		return max;
	}
}
0