結果

問題 No.2716 Falcon Method
ユーザー rin204
提出日時 2024-04-07 10:56:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 715 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 117,816 KB
最終ジャッジ日時 2024-10-01 04:25:09
合計ジャッジ時間 7,719 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

n, Q = map(int, input().split())
S = input()
H = [0]
W = [0]

H2 = [0]
W2 = [0]
for i, s in enumerate(S, 1):
    if s == "D":
        H.append(i)
        H2.append(H2[-1] + 1)
        W2.append(W2[-1])
    else:
        W.append(i)
        H2.append(H2[-1])
        W2.append(W2[-1] + 1)

for _ in range(Q):
    h, w, p = map(int, input().split())
    h += H2[p]
    w += W2[p]
    if H2[-1] == 0:
        print(w % n)
        continue
    if W2[-1] == 0:
        print(h % n)
        continue

    mi = min((h - 1) // H2[-1], (w - 1) // W2[-1])
    h -= mi * H2[-1]
    w -= mi * W2[-1]
    ans = n
    if h < H2[-1]:
        ans = min(ans, H[h])
    if w < W2[-1]:
        ans = min(ans, W[w])
    print(ans % n)
0