結果

問題 No.2716 Falcon Method
ユーザー 👑 tipstar0125tipstar0125
提出日時 2024-04-05 22:58:44
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,184 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 94,148 KB
最終ジャッジ日時 2024-04-05 22:58:54
合計ジャッジ時間 5,565 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,460 KB
testcase_01 RE -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,Q=list(map(int,input().split()))
S=list(input())
prefix_sum_D=[0 for _ in range(N+1)]
prefix_sum_R=[0 for _ in range(N+1)]
for i in range(N):
    if S[i]=="D":
        prefix_sum_D[i+1]=prefix_sum_D[i]+1
        prefix_sum_R[i+1]=prefix_sum_R[i]
    else:
        prefix_sum_R[i+1]=prefix_sum_R[i]+1
        prefix_sum_D[i+1]=prefix_sum_D[i]

for q in range(Q):
    h,w,p=list(map(int,input().split()))
    ans=p
    rotate_cnt_h=h//prefix_sum_D[-1]
    rotate_cnt_w=w//prefix_sum_R[-1]
    if rotate_cnt_h>0 and rotate_cnt_w>0:
        ans-=1

    r=h-rotate_cnt_h*prefix_sum_D[-1]
    ok=0
    ng=N
    while ng-ok>1:
        m=(ok+ng)//2
        c=0
        for i in range(m):
            if S[(i+p)%N]=="D":c+=1
        if c<=r:ok=m
        else:ng=m
    hh=ok
    
    r=w-rotate_cnt_w*prefix_sum_R[-1]
    ok=0
    ng=N
    while ng-ok>1:
        m=(ok+ng)//2
        c=0
        for i in range(m):
            if S[(i+p)%N]=="R":c+=1
        if c<=r:ok=m
        else:ng=m
    ww=ok
    
    
    if rotate_cnt_h<rotate_cnt_w:ans+=hh
    elif rotate_cnt_h>rotate_cnt_w:ans+=ww
    else:ans+=min(hh,ww)
    ans+=N
    ans%=N
    print(ans)
    
            
            
    
0