結果
問題 | No.935 う し た ぷ に き あ く ん 笑 ビ - ム |
ユーザー | tenten |
提出日時 | 2022-10-06 10:00:36 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 463 ms / 2,000 ms |
コード長 | 2,224 bytes |
コンパイル時間 | 2,672 ms |
コンパイル使用メモリ | 79,184 KB |
実行使用メモリ | 47,392 KB |
最終ジャッジ日時 | 2024-06-10 21:09:22 |
合計ジャッジ時間 | 16,269 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 91 ms
38,836 KB |
testcase_01 | AC | 151 ms
45,208 KB |
testcase_02 | AC | 157 ms
45,328 KB |
testcase_03 | AC | 222 ms
46,232 KB |
testcase_04 | AC | 251 ms
46,380 KB |
testcase_05 | AC | 209 ms
46,468 KB |
testcase_06 | AC | 219 ms
46,692 KB |
testcase_07 | AC | 246 ms
46,964 KB |
testcase_08 | AC | 334 ms
46,444 KB |
testcase_09 | AC | 267 ms
46,660 KB |
testcase_10 | AC | 292 ms
46,312 KB |
testcase_11 | AC | 389 ms
46,788 KB |
testcase_12 | AC | 45 ms
37,008 KB |
testcase_13 | AC | 45 ms
36,716 KB |
testcase_14 | AC | 44 ms
36,820 KB |
testcase_15 | AC | 44 ms
36,696 KB |
testcase_16 | AC | 43 ms
36,864 KB |
testcase_17 | AC | 267 ms
43,868 KB |
testcase_18 | AC | 284 ms
46,548 KB |
testcase_19 | AC | 231 ms
47,208 KB |
testcase_20 | AC | 315 ms
46,148 KB |
testcase_21 | AC | 96 ms
41,672 KB |
testcase_22 | AC | 187 ms
46,236 KB |
testcase_23 | AC | 47 ms
36,864 KB |
testcase_24 | AC | 93 ms
40,264 KB |
testcase_25 | AC | 93 ms
40,212 KB |
testcase_26 | AC | 71 ms
38,728 KB |
testcase_27 | AC | 56 ms
36,704 KB |
testcase_28 | AC | 78 ms
37,728 KB |
testcase_29 | AC | 80 ms
39,256 KB |
testcase_30 | AC | 82 ms
39,136 KB |
testcase_31 | AC | 79 ms
38,436 KB |
testcase_32 | AC | 88 ms
40,096 KB |
testcase_33 | AC | 336 ms
47,332 KB |
testcase_34 | AC | 309 ms
46,600 KB |
testcase_35 | AC | 314 ms
46,696 KB |
testcase_36 | AC | 225 ms
47,080 KB |
testcase_37 | AC | 316 ms
47,228 KB |
testcase_38 | AC | 229 ms
46,416 KB |
testcase_39 | AC | 304 ms
46,344 KB |
testcase_40 | AC | 295 ms
46,192 KB |
testcase_41 | AC | 323 ms
47,184 KB |
testcase_42 | AC | 341 ms
46,804 KB |
testcase_43 | AC | 357 ms
46,572 KB |
testcase_44 | AC | 153 ms
45,544 KB |
testcase_45 | AC | 335 ms
47,392 KB |
testcase_46 | AC | 132 ms
42,844 KB |
testcase_47 | AC | 191 ms
46,064 KB |
testcase_48 | AC | 289 ms
45,872 KB |
testcase_49 | AC | 215 ms
46,336 KB |
testcase_50 | AC | 286 ms
47,188 KB |
testcase_51 | AC | 259 ms
47,028 KB |
testcase_52 | AC | 239 ms
47,208 KB |
testcase_53 | AC | 463 ms
46,812 KB |
testcase_54 | AC | 265 ms
46,772 KB |
testcase_55 | AC | 84 ms
40,336 KB |
testcase_56 | AC | 303 ms
46,492 KB |
testcase_57 | AC | 249 ms
46,944 KB |
testcase_58 | AC | 45 ms
36,944 KB |
testcase_59 | AC | 46 ms
36,572 KB |
ソースコード
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(); char[] enemies = sc.next().toCharArray(); long[] sums = new long[n + 1]; int[] counts = new int[n + 1]; for (int i = 1; i <= n; i++) { sums[i] = sums[i - 1] + sc.nextInt(); counts[i] = counts[i - 1]; if (enemies[i - 1] == 'E') { counts[i]++; } } TreeMap<Long, Integer> matrix = new TreeMap<>(); matrix.put(0L, 0); for (int i = 0; i < n; i++) { for (int j = i + 1; j <= n; j++) { long s = sums[j] - sums[i]; int c = counts[j] - counts[i]; if (matrix.floorEntry(s).getValue() < c) { matrix.put(s, c); Long key = s; while ((key = matrix.higherKey(key)) != null) { if (matrix.get(key) <= c) { matrix.remove(key); } else { break; } } } } } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (q-- > 0) { sb.append(matrix.floorEntry(sc.nextLong()).getValue()).append("\n"); } System.out.print(sb); } } 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(); } }