結果
問題 | No.935 う し た ぷ に き あ く ん 笑 ビ - ム |
ユーザー |
![]() |
提出日時 | 2020-02-06 10:37:44 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 303 ms / 2,000 ms |
コード長 | 1,269 bytes |
コンパイル時間 | 2,026 ms |
コンパイル使用メモリ | 77,968 KB |
実行使用メモリ | 58,924 KB |
最終ジャッジ日時 | 2024-09-25 04:58:09 |
合計ジャッジ時間 | 16,017 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 58 |
ソースコード
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(); int[] eSums = new int[n + 1]; long[] sSums = new long[n + 1]; for (int i = 1; i <= n; i++) { eSums[i] = eSums[i - 1]; if (arr[i - 1] == 'E') { eSums[i]++; } sSums[i] = sSums[i - 1]; sSums[i] += sc.nextInt(); } int max = eSums[n]; long[] scores = new long[max + 1]; Arrays.fill(scores, Long.MAX_VALUE); scores[0] = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j <= n; j++) { int count = eSums[j] - eSums[i]; scores[count] = Math.min(scores[count], sSums[j] - sSums[i]); } } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int x = sc.nextInt(); int idx = 0; while (idx < max && scores[idx + 1] <= x) { idx++; } sb.append(idx).append("\n"); } System.out.print(sb); } }