結果
問題 | No.2716 Falcon Method |
ユーザー |
![]() |
提出日時 | 2024-04-06 00:15:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 289 ms / 2,000 ms |
コード長 | 945 bytes |
コンパイル時間 | 354 ms |
コンパイル使用メモリ | 82,440 KB |
実行使用メモリ | 104,092 KB |
最終ジャッジ日時 | 2024-10-01 03:14:21 |
合計ジャッジ時間 | 6,625 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
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)