結果

問題 No.2716 Falcon Method
ユーザー dp_ijkdp_ijk
提出日時 2024-04-05 22:34:58
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 772 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 114,080 KB
最終ジャッジ日時 2024-04-05 22:35:10
合計ジャッジ時間 10,301 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 RE -
testcase_02 AC 41 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 73 ms
72,680 KB
testcase_08 AC 73 ms
72,680 KB
testcase_09 AC 74 ms
72,680 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 602 ms
110,188 KB
testcase_13 AC 559 ms
109,428 KB
testcase_14 AC 690 ms
109,104 KB
testcase_15 AC 612 ms
109,324 KB
testcase_16 AC 649 ms
108,904 KB
testcase_17 AC 712 ms
112,332 KB
testcase_18 AC 771 ms
110,016 KB
testcase_19 AC 628 ms
108,724 KB
testcase_20 AC 545 ms
110,396 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 564 ms
104,764 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 536 ms
109,080 KB
testcase_28 AC 537 ms
109,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate
from bisect import bisect_left, bisect_right

N, Q = map(int, input().split())
S = [*input()]
D = [int(ch == "D") for ch in S]
R = [int(ch == "R") for ch in S]

Dwa = [0] + [*accumulate(D)]
Rwa = [0] + [*accumulate(R)]

DELTA = sum(D)
RHO = sum(R)


def estimate_time(X, P, PI, wa):
   t = 0
   q, r = divmod(X, PI)
   t += q*N
   X = r

   tail = wa[N] - wa[P]
   if tail < X:
      X -= tail
      t += N-P
      i = 0
   else:
      i = P
   j = bisect_left(wa, wa[i] + X)
   t += j-i
   return t


def solve(H, W, P):
   t_D = estimate_time(H, P, DELTA, Dwa)
   t_R = estimate_time(W, P, RHO, Rwa)
   t = min(t_D, t_R)
   return (P+t)%N


for _ in range(Q):
   H, W, P = map(int, input().split())
   ans = solve(H, W, P)
   print(ans)
0