結果

問題 No.2716 Falcon Method
ユーザー rlangevin
提出日時 2024-04-07 01:31:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 82,736 KB
実行使用メモリ 104,320 KB
最終ジャッジ日時 2024-10-01 04:20:09
合計ジャッジ時間 6,005 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
S = list(input())
h = S.count("D")
w = N - h
T1 = [0] * 3 * N
T2 = [0] * 3 * N
Ac1 = [0] * (3 * N + 1)
Ac2 = [0] * (3 * N + 1)
for i in range(N):
    if S[i] == "D":
        T1[i] += 1
        T1[i + N] += 1
        T1[i + 2 * N] += 1
    else:
        T2[i] += 1
        T2[i + N] += 1
        T2[i + 2 * N] += 1
        
for i in range(3 * N):
    Ac1[i + 1] = Ac1[i] + T1[i]
    Ac2[i + 1] = Ac2[i] + T2[i]
        
def BinarySearch(check, yes = 10 ** 18, no = -1):
    while abs(yes - no) != 1:
        mid = (yes + no)//2
        if check(mid):
            yes = mid
        else:
            no = mid
    return yes

def check1(m):
    return (H - h * m) > 0 and (W - w * m) > 0

def check2(r):
    x = Ac1[r] - Ac1[P]
    y = Ac2[r] - Ac2[P]
    return H - x <= 0 or W - y <= 0

def div(x, y):
    if y == 0:
        return 10 ** 18
    return x // y

for _ in range(Q):
    H, W, P = map(int, input().split())
    m = min(div(H - 1, h), div(W - 1, w))
    H -= m * h
    W -= m * w
    print(BinarySearch(check2, 3 * N, P)%N)
0