結果

問題 No.935 う し た ぷ に き あ く ん 笑 ビ - ム
ユーザー tenten
提出日時 2020-08-26 19:00:44
言語 Java
(openjdk 23)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 1,390 bytes
コンパイル時間 2,459 ms
コンパイル使用メモリ 77,756 KB
実行使用メモリ 46,240 KB
最終ジャッジ日時 2024-11-07 13:23:14
合計ジャッジ時間 16,516 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 58
権限があれば一括ダウンロードができます

ソースコード

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