結果

問題 No.2716 Falcon Method
ユーザー detteiuudetteiuu
提出日時 2024-04-11 01:14:53
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 894 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 82,696 KB
実行使用メモリ 115,960 KB
最終ジャッジ日時 2024-04-11 01:15:03
合計ジャッジ時間 9,070 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,992 KB
testcase_01 RE -
testcase_02 AC 39 ms
52,224 KB
testcase_03 AC 39 ms
52,608 KB
testcase_04 AC 40 ms
52,608 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 72 ms
70,400 KB
testcase_08 AC 70 ms
70,144 KB
testcase_09 AC 76 ms
70,288 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 266 ms
110,956 KB
testcase_13 AC 237 ms
109,376 KB
testcase_14 AC 288 ms
106,644 KB
testcase_15 AC 250 ms
107,868 KB
testcase_16 AC 275 ms
105,240 KB
testcase_17 AC 291 ms
107,112 KB
testcase_18 AC 322 ms
111,636 KB
testcase_19 AC 269 ms
106,284 KB
testcase_20 AC 253 ms
107,492 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 320 ms
114,684 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 426 ms
114,532 KB
testcase_28 AC 376 ms
114,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left

N, Q = map(int, input().split())
S = input()
HWP = [list(map(int, input().split())) for _ in range(Q)]

cumD = [0]
cumR = [0]
for i in range(N):
    if S[i] == "D":
        cumD.append(cumD[-1]+1)
        cumR.append(cumR[-1])
    else:
        cumD.append(cumD[-1])
        cumR.append(cumR[-1]+1)

for i in range(Q):
    H, W, P = HWP[i]
    if cumD[-1]-cumD[P] < H and cumR[-1]-cumR[P] < W:
        h, w = cumD[-1]-cumD[P], cumR[-1]-cumR[P]
        C = min((H-h-1)//cumD[-1], (W-w-1)//cumR[-1])
        h += cumD[-1]*C
        w += cumR[-1]*C
        H -= h
        W -= w
        P = 0
    if cumD[-1]-cumD[P] >= H and cumR[-1]-cumR[P] >= W:
        print(min(bisect_left(cumD, cumD[P]+H), bisect_left(cumR, cumR[P]+W)) % N)
    elif cumD[-1]-cumD[P] >= H:
        print(bisect_left(cumD, cumD[P]+H)%N)
    else:
        print(bisect_left(cumR, cumR[P]+W)%N)
0