結果
問題 | No.1238 選抜クラス |
ユーザー |
![]() |
提出日時 | 2020-09-28 11:49:54 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 372 ms / 2,000 ms |
コード長 | 1,296 bytes |
コンパイル時間 | 3,160 ms |
コンパイル使用メモリ | 78,972 KB |
実行使用メモリ | 61,704 KB |
最終ジャッジ日時 | 2024-07-01 20:51:06 |
合計ジャッジ時間 | 11,861 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
import java.util.*; public class Main { static final int MOD = 1000000007; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); TreeMap<Integer, Integer> map = new TreeMap<>(); map.put(0, 1); for (int i = 0; i < n; i++) { int x = sc.nextInt() - k; if (x >= 0) { Integer key = Integer.MAX_VALUE; while ((key = map.lowerKey(key)) != null) { int next = key + x; if (map.containsKey(next)) { map.put(next, (map.get(next) + map.get(key)) % MOD); } else { map.put(next, map.get(key)); } } } else { Integer key = Integer.MIN_VALUE; while ((key = map.higherKey(key)) != null) { int next = key + x; if (map.containsKey(next)) { map.put(next, (map.get(next) + map.get(key)) % MOD); } else { map.put(next, map.get(key)); } } } } int total = - 1; for (Map.Entry<Integer, Integer> entry : map.entrySet()) { if (entry.getKey() >= 0) { total += entry.getValue(); total %= MOD; } } System.out.println(total); } }