結果

問題 No.935 う し た ぷ に き あ く ん 笑 ビ - ム
ユーザー tentententen
提出日時 2023-08-01 13:52:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 450 ms / 2,000 ms
コード長 2,697 bytes
コンパイル時間 2,364 ms
コンパイル使用メモリ 92,980 KB
実行使用メモリ 47,672 KB
最終ジャッジ日時 2024-04-19 13:12:05
合計ジャッジ時間 16,547 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
39,036 KB
testcase_01 AC 149 ms
45,940 KB
testcase_02 AC 156 ms
45,156 KB
testcase_03 AC 226 ms
46,084 KB
testcase_04 AC 259 ms
47,384 KB
testcase_05 AC 210 ms
46,880 KB
testcase_06 AC 216 ms
46,804 KB
testcase_07 AC 256 ms
46,492 KB
testcase_08 AC 349 ms
47,024 KB
testcase_09 AC 269 ms
47,184 KB
testcase_10 AC 305 ms
46,688 KB
testcase_11 AC 450 ms
46,624 KB
testcase_12 AC 50 ms
36,964 KB
testcase_13 AC 49 ms
37,148 KB
testcase_14 AC 47 ms
36,956 KB
testcase_15 AC 47 ms
37,184 KB
testcase_16 AC 46 ms
37,112 KB
testcase_17 AC 274 ms
44,532 KB
testcase_18 AC 296 ms
46,348 KB
testcase_19 AC 223 ms
46,888 KB
testcase_20 AC 326 ms
46,892 KB
testcase_21 AC 97 ms
41,456 KB
testcase_22 AC 187 ms
45,956 KB
testcase_23 AC 50 ms
37,192 KB
testcase_24 AC 88 ms
40,380 KB
testcase_25 AC 91 ms
40,176 KB
testcase_26 AC 80 ms
38,648 KB
testcase_27 AC 52 ms
37,440 KB
testcase_28 AC 58 ms
37,560 KB
testcase_29 AC 82 ms
39,468 KB
testcase_30 AC 67 ms
38,256 KB
testcase_31 AC 75 ms
38,280 KB
testcase_32 AC 93 ms
40,308 KB
testcase_33 AC 329 ms
47,232 KB
testcase_34 AC 311 ms
46,256 KB
testcase_35 AC 312 ms
47,212 KB
testcase_36 AC 235 ms
46,860 KB
testcase_37 AC 326 ms
46,916 KB
testcase_38 AC 244 ms
47,348 KB
testcase_39 AC 324 ms
46,100 KB
testcase_40 AC 304 ms
45,992 KB
testcase_41 AC 327 ms
46,504 KB
testcase_42 AC 379 ms
46,560 KB
testcase_43 AC 318 ms
46,724 KB
testcase_44 AC 145 ms
45,952 KB
testcase_45 AC 344 ms
47,672 KB
testcase_46 AC 127 ms
42,032 KB
testcase_47 AC 195 ms
45,956 KB
testcase_48 AC 281 ms
46,024 KB
testcase_49 AC 212 ms
46,416 KB
testcase_50 AC 294 ms
47,320 KB
testcase_51 AC 269 ms
46,624 KB
testcase_52 AC 245 ms
47,404 KB
testcase_53 AC 416 ms
46,472 KB
testcase_54 AC 275 ms
46,684 KB
testcase_55 AC 83 ms
40,176 KB
testcase_56 AC 326 ms
46,504 KB
testcase_57 AC 278 ms
47,216 KB
testcase_58 AC 61 ms
36,732 KB
testcase_59 AC 52 ms
36,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        char[] inputs = sc.next().toCharArray();
        int[] enemies = new int[n + 1];
        long[] sums = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            sums[i] = sums[i - 1] + sc.nextInt();
            enemies[i] = enemies[i - 1];
            if (inputs[i - 1] == 'E') {
                enemies[i]++;
            }
        }
        TreeMap<Long, Integer> counts = new TreeMap<>();
        counts.put(0L, 0);
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j <= n; j++) {
                Long x = sums[j] - sums[i];
                int y = enemies[j] - enemies[i];
                if (counts.floorEntry(x).getValue() >= y) {
                    continue;
                }
                counts.put(x, y);
                while ((x = counts.higherKey(x)) != null) {
                    if (counts.get(x) <= y) {
                        counts.remove(x);
                    } else {
                        break;
                    }
                }
            }
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while(q-- > 0) {
            sb.append(counts.floorEntry(sc.nextLong()).getValue()).append("\n");
        }
        System.out.print(sb);
    }
} 
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0