結果

問題 No.935 う し た ぷ に き あ く ん 笑 ビ - ム
コンテスト
ユーザー koheijkt
提出日時 2026-03-12 17:09:38
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,737 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,379 ms
コンパイル使用メモリ 85,012 KB
実行使用メモリ 80,168 KB
最終ジャッジ日時 2026-03-12 17:09:45
合計ジャッジ時間 6,164 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 58
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys, math
sys.setrecursionlimit(10**8)
sys.set_int_max_str_digits(0)
INF = 1e18
MOD = 998244353
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import product, combinations, permutations, groupby, accumulate
from heapq import heapify, heappop, heappush
input = sys.stdin.readline
def I():   return input().rstrip()
def II():  return int(input().rstrip())
def IS():  return input().rstrip().split()
def MII(): return map(int, input().rstrip().split())
def LI():  return list(input().rstrip())
def TII(): return tuple(map(int, input().rstrip().split()))
def LII(): return list(map(int, input().rstrip().split()))
def LSI(): return list(map(str, input().rstrip().split()))
def GMI(): return list(map(lambda x: int(x) - 1, input().rstrip().split()))
def kiriage(a, b): return (a+b-1)//b

def chmax(DP,i,v):
    if DP[i] < v: DP[i] = v
def chmin(DP,i,v):
    if DP[i] > v: DP[i] = v

def cnt_ika(li, x): # x 以下の要素数
    return bisect_right(li, x)

def cnt_miman(li, x): # x 未満の要素数
    return bisect_left(li, x)

def cnt_ijou(li, x): # x 以上の要素数
    return len(li) - cnt_miman(li, x)

def cnt_choka(li, x): # x より大きい要素数
    return len(li) - cnt_ika(li, x)

N = II()
S = I()
S = list(map(lambda x: 1 if x == 'E' else 0, S))
rS = list(accumulate(S, initial=0))
A = LII()
rA = list(accumulate(A, initial=0))

Q = II()
query = LII()

minimum_effort = [INF] * (N + 1)
minimum_effort[0] = 0

for l in range(N):
    for r in range(l, N):
        enemy = rS[r + 1] - rS[l]
        required_effort = rA[r + 1] - rA[l]
        chmin(minimum_effort, enemy, required_effort)

for q in query:
    print(cnt_ika(minimum_effort, q) - 1)
0