結果

問題 No.1238 選抜クラス
ユーザー tentententen
提出日時 2021-12-01 08:52:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 2,069 bytes
コンパイル時間 2,212 ms
コンパイル使用メモリ 75,368 KB
実行使用メモリ 60,264 KB
最終ジャッジ日時 2023-09-17 11:38:26
合計ジャッジ時間 7,670 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,380 KB
testcase_01 AC 45 ms
49,544 KB
testcase_02 AC 49 ms
49,520 KB
testcase_03 AC 45 ms
49,636 KB
testcase_04 AC 45 ms
49,452 KB
testcase_05 AC 44 ms
49,768 KB
testcase_06 AC 45 ms
49,636 KB
testcase_07 AC 46 ms
49,632 KB
testcase_08 AC 49 ms
49,832 KB
testcase_09 AC 68 ms
52,132 KB
testcase_10 AC 46 ms
49,472 KB
testcase_11 AC 55 ms
50,160 KB
testcase_12 AC 50 ms
49,604 KB
testcase_13 AC 51 ms
49,492 KB
testcase_14 AC 47 ms
49,496 KB
testcase_15 AC 60 ms
51,492 KB
testcase_16 AC 60 ms
51,296 KB
testcase_17 AC 226 ms
59,732 KB
testcase_18 AC 185 ms
58,900 KB
testcase_19 AC 220 ms
57,580 KB
testcase_20 AC 237 ms
60,264 KB
testcase_21 AC 234 ms
59,808 KB
testcase_22 AC 47 ms
49,492 KB
testcase_23 AC 76 ms
51,084 KB
testcase_24 AC 69 ms
51,104 KB
testcase_25 AC 47 ms
49,548 KB
testcase_26 AC 198 ms
57,804 KB
testcase_27 AC 240 ms
57,856 KB
testcase_28 AC 203 ms
59,444 KB
testcase_29 AC 195 ms
59,568 KB
testcase_30 AC 89 ms
52,308 KB
testcase_31 AC 113 ms
54,460 KB
testcase_32 AC 200 ms
58,812 KB
testcase_33 AC 46 ms
49,384 KB
testcase_34 AC 140 ms
55,304 KB
testcase_35 AC 100 ms
52,316 KB
testcase_36 AC 83 ms
52,560 KB
testcase_37 AC 89 ms
52,840 KB
testcase_38 AC 195 ms
59,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt() - k;
        }
        TreeMap<Integer, Integer> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            if (values[i] < 0) {
                Integer key = Integer.MIN_VALUE;
                while ((key = map.higherKey(key)) != null) {
                    int next = key + values[i];
                    map.put(next, (map.getOrDefault(next, 0) + map.get(key)) % MOD);
                }
            } else {
                Integer key = Integer.MAX_VALUE;
                while ((key = map.lowerKey(key)) != null) {
                    int next = key + values[i];
                    map.put(next, (map.getOrDefault(next, 0) + map.get(key)) % MOD);
                }
           }
           map.put(values[i], (map.getOrDefault(values[i], 0) + 1) % MOD);
        }
        int ans = 0;
        for (int x : map.keySet()) {
            if (x < 0) {
                continue;
            }
            ans += map.get(x);
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0