結果

問題 No.935 う し た ぷ に き あ く ん 笑 ビ - ム
ユーザー tentententen
提出日時 2020-08-26 19:00:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 1,390 bytes
コンパイル時間 2,075 ms
コンパイル使用メモリ 77,984 KB
実行使用メモリ 46,532 KB
最終ジャッジ日時 2024-04-25 03:38:59
合計ジャッジ時間 14,516 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 176 ms
42,912 KB
testcase_01 AC 188 ms
43,548 KB
testcase_02 AC 184 ms
42,452 KB
testcase_03 AC 198 ms
43,676 KB
testcase_04 AC 201 ms
43,680 KB
testcase_05 AC 192 ms
42,436 KB
testcase_06 AC 199 ms
44,184 KB
testcase_07 AC 200 ms
43,952 KB
testcase_08 AC 237 ms
45,916 KB
testcase_09 AC 209 ms
44,144 KB
testcase_10 AC 211 ms
44,580 KB
testcase_11 AC 234 ms
45,956 KB
testcase_12 AC 115 ms
41,180 KB
testcase_13 AC 111 ms
41,300 KB
testcase_14 AC 112 ms
40,976 KB
testcase_15 AC 118 ms
40,956 KB
testcase_16 AC 111 ms
41,284 KB
testcase_17 AC 243 ms
46,532 KB
testcase_18 AC 204 ms
43,552 KB
testcase_19 AC 213 ms
44,720 KB
testcase_20 AC 215 ms
44,116 KB
testcase_21 AC 170 ms
42,316 KB
testcase_22 AC 183 ms
42,364 KB
testcase_23 AC 126 ms
41,292 KB
testcase_24 AC 137 ms
41,884 KB
testcase_25 AC 146 ms
41,776 KB
testcase_26 AC 127 ms
41,832 KB
testcase_27 AC 119 ms
41,076 KB
testcase_28 AC 132 ms
41,664 KB
testcase_29 AC 135 ms
41,508 KB
testcase_30 AC 144 ms
41,848 KB
testcase_31 AC 130 ms
41,292 KB
testcase_32 AC 137 ms
40,808 KB
testcase_33 AC 218 ms
44,392 KB
testcase_34 AC 219 ms
44,516 KB
testcase_35 AC 208 ms
44,968 KB
testcase_36 AC 193 ms
43,048 KB
testcase_37 AC 195 ms
44,040 KB
testcase_38 AC 202 ms
44,392 KB
testcase_39 AC 220 ms
45,344 KB
testcase_40 AC 217 ms
44,880 KB
testcase_41 AC 217 ms
44,624 KB
testcase_42 AC 210 ms
44,540 KB
testcase_43 AC 226 ms
44,760 KB
testcase_44 AC 192 ms
43,668 KB
testcase_45 AC 242 ms
45,548 KB
testcase_46 AC 182 ms
42,620 KB
testcase_47 AC 199 ms
43,484 KB
testcase_48 AC 210 ms
43,636 KB
testcase_49 AC 201 ms
44,004 KB
testcase_50 AC 211 ms
43,808 KB
testcase_51 AC 211 ms
44,280 KB
testcase_52 AC 213 ms
43,856 KB
testcase_53 AC 229 ms
45,324 KB
testcase_54 AC 202 ms
43,164 KB
testcase_55 AC 158 ms
42,408 KB
testcase_56 AC 225 ms
44,600 KB
testcase_57 AC 207 ms
43,796 KB
testcase_58 AC 123 ms
41,228 KB
testcase_59 AC 104 ms
40,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        long[] sums = new long[n + 1];
        int[] counts = new int[n + 1];
        int count = 0;
        for (int i = 1; i <= n; i++) {
            sums[i] = sums[i - 1] + sc.nextInt();
            if (arr[i - 1] == 'E') {
                count++;
            }
            counts[i] = count;
        }
        long[] mins = new long[count + 1];
        Arrays.fill(mins, Long.MAX_VALUE);
        mins[0] = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j <= n; j++) {
                int enemy = counts[j] - counts[i];
                mins[enemy] = Math.min(mins[enemy], sums[j] - sums[i]);
            }
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt();
            int left = 0;
            int right = count + 1;
            while (right - left > 1) {
                int m = (left + right) / 2;
                if (mins[m] <= x) {
                    left = m;
                } else {
                    right = m;
                }
            }
            sb.append(left).append("\n");
        }
        System.out.print(sb);
    }
}
0