結果
| 問題 |
No.2716 Falcon Method
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-05 22:58:44 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,184 bytes |
| コンパイル時間 | 1,060 ms |
| コンパイル使用メモリ | 82,472 KB |
| 実行使用メモリ | 95,256 KB |
| 最終ジャッジ日時 | 2024-10-01 02:58:37 |
| 合計ジャッジ時間 | 5,701 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 6 RE * 5 TLE * 1 -- * 16 |
ソースコード
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)