結果

問題 No.935 う し た ぷ に き あ く ん 笑 ビ - ム
ユーザー tentententen
提出日時 2022-10-06 10:00:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 426 ms / 2,000 ms
コード長 2,224 bytes
コンパイル時間 3,285 ms
コンパイル使用メモリ 83,488 KB
実行使用メモリ 58,784 KB
最終ジャッジ日時 2023-08-30 21:46:03
合計ジャッジ時間 18,646 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
51,676 KB
testcase_01 AC 163 ms
57,308 KB
testcase_02 AC 169 ms
57,464 KB
testcase_03 AC 249 ms
58,152 KB
testcase_04 AC 281 ms
58,524 KB
testcase_05 AC 229 ms
58,784 KB
testcase_06 AC 245 ms
58,344 KB
testcase_07 AC 265 ms
58,504 KB
testcase_08 AC 361 ms
58,056 KB
testcase_09 AC 290 ms
57,672 KB
testcase_10 AC 307 ms
57,568 KB
testcase_11 AC 424 ms
58,620 KB
testcase_12 AC 42 ms
49,412 KB
testcase_13 AC 41 ms
49,472 KB
testcase_14 AC 41 ms
47,320 KB
testcase_15 AC 40 ms
49,300 KB
testcase_16 AC 41 ms
49,336 KB
testcase_17 AC 272 ms
55,412 KB
testcase_18 AC 307 ms
58,480 KB
testcase_19 AC 256 ms
58,380 KB
testcase_20 AC 378 ms
57,696 KB
testcase_21 AC 110 ms
55,188 KB
testcase_22 AC 215 ms
58,020 KB
testcase_23 AC 46 ms
49,396 KB
testcase_24 AC 93 ms
53,056 KB
testcase_25 AC 94 ms
53,088 KB
testcase_26 AC 70 ms
50,936 KB
testcase_27 AC 51 ms
49,432 KB
testcase_28 AC 58 ms
50,944 KB
testcase_29 AC 83 ms
53,156 KB
testcase_30 AC 79 ms
52,192 KB
testcase_31 AC 62 ms
50,816 KB
testcase_32 AC 87 ms
52,192 KB
testcase_33 AC 345 ms
58,496 KB
testcase_34 AC 338 ms
58,296 KB
testcase_35 AC 331 ms
58,452 KB
testcase_36 AC 254 ms
56,544 KB
testcase_37 AC 345 ms
56,292 KB
testcase_38 AC 250 ms
58,668 KB
testcase_39 AC 338 ms
57,432 KB
testcase_40 AC 312 ms
57,832 KB
testcase_41 AC 343 ms
58,600 KB
testcase_42 AC 352 ms
58,268 KB
testcase_43 AC 336 ms
57,808 KB
testcase_44 AC 160 ms
57,628 KB
testcase_45 AC 372 ms
58,756 KB
testcase_46 AC 135 ms
55,752 KB
testcase_47 AC 219 ms
56,868 KB
testcase_48 AC 287 ms
57,540 KB
testcase_49 AC 239 ms
58,180 KB
testcase_50 AC 304 ms
58,068 KB
testcase_51 AC 290 ms
58,200 KB
testcase_52 AC 251 ms
58,464 KB
testcase_53 AC 426 ms
58,784 KB
testcase_54 AC 286 ms
58,316 KB
testcase_55 AC 83 ms
53,556 KB
testcase_56 AC 316 ms
58,156 KB
testcase_57 AC 258 ms
58,456 KB
testcase_58 AC 43 ms
49,372 KB
testcase_59 AC 42 ms
49,784 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();
        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();
    }
    
}
0