結果

問題 No.365 ジェンガソート
ユーザー keitamido
提出日時 2017-06-10 16:16:13
言語 Java
(openjdk 23)
結果
AC  
実行時間 636 ms / 2,000 ms
コード長 545 bytes
コンパイル時間 2,343 ms
コンパイル使用メモリ 75,032 KB
実行使用メモリ 64,152 KB
最終ジャッジ日時 2024-09-24 15:42:33
合計ジャッジ時間 18,034 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class JengaSortFix3 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int length = sc.nextInt();
		int cnt = length - 1;
		HashSet<Integer> nset = new HashSet<Integer>();
		int maxInSet = sc.nextInt();
		nset.add(maxInSet);
		for (int i = 0; i < length - 1; i++) {
			int next = sc.nextInt();
			if (next > maxInSet) {
				maxInSet = next;
				if (nset.contains(next - 1)) {
					cnt--;
				} else {
					cnt = length - 1;
				}
			nset.add(next);
			}
		}
		System.out.println(cnt);
	}
}
0