結果

問題 No.1692 Expectations
ユーザー みーすけみーすけ
提出日時 2021-10-01 21:44:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 879 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 2,328 ms
コンパイル使用メモリ 77,152 KB
実行使用メモリ 75,324 KB
最終ジャッジ日時 2023-09-26 16:53:55
合計ジャッジ時間 12,383 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
56,660 KB
testcase_01 AC 155 ms
56,956 KB
testcase_02 AC 180 ms
56,260 KB
testcase_03 AC 221 ms
57,504 KB
testcase_04 AC 177 ms
57,164 KB
testcase_05 AC 223 ms
59,080 KB
testcase_06 AC 214 ms
56,532 KB
testcase_07 AC 155 ms
57,016 KB
testcase_08 AC 215 ms
57,064 KB
testcase_09 AC 168 ms
56,912 KB
testcase_10 AC 748 ms
65,048 KB
testcase_11 AC 708 ms
64,716 KB
testcase_12 AC 155 ms
56,668 KB
testcase_13 AC 155 ms
56,864 KB
testcase_14 AC 364 ms
60,436 KB
testcase_15 AC 784 ms
68,920 KB
testcase_16 AC 356 ms
60,432 KB
testcase_17 AC 590 ms
62,732 KB
testcase_18 AC 444 ms
60,572 KB
testcase_19 AC 879 ms
71,200 KB
testcase_20 AC 750 ms
72,676 KB
testcase_21 AC 828 ms
75,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int min = 0;
        if(n==m && 1<=a[0] && a[0]<=m){
            boolean allSame = true;
            for (int i = 1; i < n; i++) {
                if (a[i] != a[0]) {
                    allSame = false;
                    break;
                }
            }
            if (allSame) {
                min = 1;
            }
        }
        
        int max = n;
        HashSet<Integer> hs = new HashSet<Integer>();
        for (int i = 0; i < n; i++) {
            if (1 <= a[i] && a[i] <= m) {
                if (hs.contains(a[i])) {
                    max--;
                } else {
                    hs.add(a[i]);
                }
            } else {
                max--;
            }
        }
        System.out.println(max + " " + min);
    }
}
0