結果

問題 No.2716 Falcon Method
ユーザー titiatitia
提出日時 2024-04-06 00:15:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 103,464 KB
最終ジャッジ日時 2024-04-06 00:15:37
合計ジャッジ時間 7,040 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 59 ms
66,504 KB
testcase_07 AC 62 ms
68,592 KB
testcase_08 AC 61 ms
68,596 KB
testcase_09 AC 66 ms
68,592 KB
testcase_10 AC 59 ms
66,504 KB
testcase_11 AC 260 ms
103,284 KB
testcase_12 AC 236 ms
102,728 KB
testcase_13 AC 194 ms
102,720 KB
testcase_14 AC 249 ms
96,788 KB
testcase_15 AC 202 ms
99,620 KB
testcase_16 AC 237 ms
97,064 KB
testcase_17 AC 254 ms
97,060 KB
testcase_18 AC 297 ms
99,636 KB
testcase_19 AC 253 ms
96,800 KB
testcase_20 AC 231 ms
99,520 KB
testcase_21 AC 225 ms
97,236 KB
testcase_22 AC 244 ms
103,464 KB
testcase_23 AC 258 ms
99,676 KB
testcase_24 AC 235 ms
103,464 KB
testcase_25 AC 37 ms
53,460 KB
testcase_26 AC 37 ms
53,460 KB
testcase_27 AC 235 ms
102,740 KB
testcase_28 AC 245 ms
102,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,Q=map(int,input().split())
S=input().strip()

D=[0]
R=[0]
for s in S:
    D.append(D[-1])
    R.append(R[-1])

    if s=="D":
        D[-1]+=1
    else:
        R[-1]+=1


for queries in range(Q):
    H,W,P=map(int,input().split())

    # 何歩で下にたどりつくか?

    OK=2*10**9+10
    NG=0

    while OK>NG+1:
        mid=(OK+NG)//2

        #print(mid,P,N)

        if mid+P<=N:
            down=D[mid+P]-D[P]
            right=R[mid+P]-R[P]
            #print("!",mid,down,right)
        else:
            down=D[-1]-D[P]
            right=R[-1]-R[P]

            midx=mid-(N-P)

            kk=midx//N
            rest=midx%N

            down+=kk*D[-1]
            right+=kk*R[-1]

            down+=D[rest]
            right+=R[rest]

        #print(mid,down,right)

        if H<=down or W<=right:
            OK=mid
        else:
            NG=mid
            
    print((OK+P)%N)

0