結果

問題 No.2716 Falcon Method
ユーザー rlangevinrlangevin
提出日時 2024-04-07 01:39:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 986 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 97,592 KB
最終ジャッジ日時 2024-04-07 01:39:17
合計ジャッジ時間 6,822 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 59 ms
66,364 KB
testcase_07 AC 62 ms
68,440 KB
testcase_08 AC 62 ms
68,440 KB
testcase_09 AC 61 ms
68,436 KB
testcase_10 AC 62 ms
68,440 KB
testcase_11 AC 268 ms
96,384 KB
testcase_12 AC 237 ms
96,296 KB
testcase_13 AC 206 ms
96,780 KB
testcase_14 AC 253 ms
93,568 KB
testcase_15 AC 226 ms
95,760 KB
testcase_16 AC 267 ms
93,492 KB
testcase_17 AC 250 ms
94,220 KB
testcase_18 AC 276 ms
95,036 KB
testcase_19 AC 232 ms
92,768 KB
testcase_20 AC 208 ms
95,488 KB
testcase_21 AC 221 ms
93,988 KB
testcase_22 AC 238 ms
97,576 KB
testcase_23 AC 249 ms
97,592 KB
testcase_24 AC 241 ms
97,576 KB
testcase_25 AC 36 ms
53,460 KB
testcase_26 AC 37 ms
53,460 KB
testcase_27 AC 266 ms
97,448 KB
testcase_28 AC 253 ms
97,448 KB
権限があれば一括ダウンロードができます

ソースコード

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] * 2 * N
T2 = [0] * 2 * N
Ac1 = [0] * (2 * N + 1)
Ac2 = [0] * (2 * N + 1)
for i in range(N):
    if S[i] == "D":
        T1[i] += 1
        T1[i + N] += 1
    else:
        T2[i] += 1
        T2[i + N] += 1
        
for i in range(2 * 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 check(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(check, 2 * N, P)%N)
0