結果

問題 No.1285 ゴミ捨て
ユーザー tentententen
提出日時 2022-09-26 18:31:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 427 ms / 2,000 ms
コード長 2,180 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 83,516 KB
実行使用メモリ 63,124 KB
最終ジャッジ日時 2023-08-24 02:59:42
合計ジャッジ時間 9,641 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,800 KB
testcase_01 AC 42 ms
49,912 KB
testcase_02 AC 45 ms
50,060 KB
testcase_03 AC 44 ms
49,804 KB
testcase_04 AC 41 ms
50,168 KB
testcase_05 AC 44 ms
49,872 KB
testcase_06 AC 45 ms
50,124 KB
testcase_07 AC 395 ms
60,988 KB
testcase_08 AC 126 ms
53,972 KB
testcase_09 AC 271 ms
59,628 KB
testcase_10 AC 386 ms
61,220 KB
testcase_11 AC 367 ms
61,164 KB
testcase_12 AC 305 ms
59,784 KB
testcase_13 AC 303 ms
58,884 KB
testcase_14 AC 394 ms
61,192 KB
testcase_15 AC 324 ms
58,952 KB
testcase_16 AC 193 ms
57,952 KB
testcase_17 AC 194 ms
56,696 KB
testcase_18 AC 191 ms
57,276 KB
testcase_19 AC 260 ms
60,080 KB
testcase_20 AC 182 ms
57,784 KB
testcase_21 AC 211 ms
58,672 KB
testcase_22 AC 421 ms
63,124 KB
testcase_23 AC 427 ms
59,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        Unit[] units = new Unit[n];
        for (int i = 0; i < n; i++) {
            units[i] = new Unit(i, sc.nextInt());
        }
        Arrays.sort(units);
        TreeSet<Unit> all = new TreeSet<>();
        for (Unit x : units) {
            all.add(x);
            Unit low = new Unit(-1, x.value - 1);
            Unit next = all.lower(low);
            if (next != null) {
                all.remove(next);
            }
        }
        System.out.println(all.size());
    }
    
    static class Unit implements Comparable<Unit> {
        int idx;
        int value;
        
        public Unit(int idx, int value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Unit another) {
            if (value == another.value) {
                return idx - another.idx;
            } else  {
                return value - another.value;
            }
        }
        
        public int hashCode() {
            return idx;
        }
        
        public boolean equals(Object o) {
            Unit u = (Unit)o;
            return idx == u.idx && value == u.value;
        }
        
        public String toString() {
            return idx + ":" + value;
        }
    }
}
    
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0