結果

問題 No.935 う し た ぷ に き あ く ん 笑 ビ - ム
ユーザー ks2mks2m
提出日時 2019-11-29 22:33:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 598 ms / 2,000 ms
コード長 1,529 bytes
コンパイル時間 2,540 ms
コンパイル使用メモリ 75,584 KB
実行使用メモリ 56,508 KB
最終ジャッジ日時 2023-10-12 06:28:57
合計ジャッジ時間 11,626 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
52,188 KB
testcase_01 AC 109 ms
51,184 KB
testcase_02 AC 71 ms
50,664 KB
testcase_03 AC 115 ms
51,284 KB
testcase_04 AC 114 ms
53,048 KB
testcase_05 AC 74 ms
51,236 KB
testcase_06 AC 144 ms
53,084 KB
testcase_07 AC 139 ms
53,172 KB
testcase_08 AC 148 ms
53,016 KB
testcase_09 AC 145 ms
52,900 KB
testcase_10 AC 139 ms
53,436 KB
testcase_11 AC 163 ms
54,480 KB
testcase_12 AC 42 ms
49,456 KB
testcase_13 AC 42 ms
49,620 KB
testcase_14 AC 42 ms
49,836 KB
testcase_15 AC 41 ms
47,328 KB
testcase_16 AC 41 ms
49,316 KB
testcase_17 AC 598 ms
56,508 KB
testcase_18 AC 125 ms
53,384 KB
testcase_19 AC 146 ms
52,988 KB
testcase_20 AC 144 ms
54,804 KB
testcase_21 AC 100 ms
51,560 KB
testcase_22 AC 73 ms
52,500 KB
testcase_23 AC 54 ms
50,092 KB
testcase_24 AC 109 ms
54,368 KB
testcase_25 AC 116 ms
53,924 KB
testcase_26 AC 111 ms
54,152 KB
testcase_27 AC 74 ms
52,300 KB
testcase_28 AC 92 ms
53,888 KB
testcase_29 AC 117 ms
53,384 KB
testcase_30 AC 96 ms
54,036 KB
testcase_31 AC 94 ms
53,332 KB
testcase_32 AC 124 ms
54,172 KB
testcase_33 AC 144 ms
54,372 KB
testcase_34 AC 152 ms
54,520 KB
testcase_35 AC 157 ms
54,452 KB
testcase_36 AC 101 ms
53,008 KB
testcase_37 AC 150 ms
54,432 KB
testcase_38 AC 147 ms
53,392 KB
testcase_39 AC 153 ms
54,640 KB
testcase_40 AC 153 ms
53,804 KB
testcase_41 AC 164 ms
54,452 KB
testcase_42 AC 145 ms
54,368 KB
testcase_43 AC 165 ms
54,500 KB
testcase_44 AC 138 ms
53,020 KB
testcase_45 AC 163 ms
54,160 KB
testcase_46 AC 114 ms
52,360 KB
testcase_47 AC 140 ms
52,884 KB
testcase_48 AC 135 ms
52,996 KB
testcase_49 AC 131 ms
53,096 KB
testcase_50 AC 137 ms
54,492 KB
testcase_51 AC 148 ms
53,060 KB
testcase_52 AC 134 ms
53,268 KB
testcase_53 AC 160 ms
54,144 KB
testcase_54 AC 124 ms
53,320 KB
testcase_55 AC 79 ms
50,524 KB
testcase_56 AC 152 ms
54,596 KB
testcase_57 AC 137 ms
52,792 KB
testcase_58 AC 43 ms
49,456 KB
testcase_59 AC 43 ms
49,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		char[] s = br.readLine().toCharArray();
		String[] sa = br.readLine().split(" ");
		long[] a = new long[n + 1];
		for (int i = 0; i < n; i++) {
			a[i + 1] = Long.parseLong(sa[i]);
		}
		int q = Integer.parseInt(br.readLine());
		sa = br.readLine().split(" ");
		long[] k = new long[q];
		for (int i = 0; i < q; i++) {
			k[i] = Long.parseLong(sa[i]);
		}
		br.close();

		int[] e = new int[n + 1];
		for (int i = 0; i < n; i++) {
			e[i + 1] = e[i];
			if (s[i] == 'E') {
				e[i + 1]++;
			}
		}

		for (int i = 1; i < a.length; i++) {
			a[i] += a[i - 1];
		}

		TreeMap<Long, Integer> map = new TreeMap<>();
		map.put(0L, 0);
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n + 1; j++) {
				long b = a[j] - a[i];
				if (b > 1000000000) {
					break;
				}
				int c = e[j] - e[i];
				if (map.containsKey(b)) {
					map.put(b, Math.max(c, map.get(b)));
				} else {
					map.put(b, c);
				}
			}
		}
		Long[] arr = map.keySet().toArray(new Long[0]);
		int v = map.get(arr[0]);
		for (int i = 1; i < arr.length; i++) {
			int vi = map.get(arr[i]);
			if (vi > v) {
				v = vi;
			} else {
				map.remove(arr[i]);
			}
		}

		for (int i = 0; i < q; i++) {
			System.out.println(map.floorEntry(k[i]).getValue());
		}
	}
}
0