結果
問題 | No.2716 Falcon Method |
ユーザー |
![]() |
提出日時 | 2024-04-07 01:28:10 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 303 ms / 2,000 ms |
コード長 | 1,035 bytes |
コンパイル時間 | 300 ms |
コンパイル使用メモリ | 82,124 KB |
実行使用メモリ | 104,232 KB |
最終ジャッジ日時 | 2024-10-01 04:19:57 |
合計ジャッジ時間 | 6,872 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
import sysinput = sys.stdin.readlineN, Q = map(int, input().split())S = list(input())h = S.count("D")w = N - hT1 = [0] * 3 * NT2 = [0] * 3 * NAc1 = [0] * (3 * N + 1)Ac2 = [0] * (3 * N + 1)for i in range(N):if S[i] == "D":T1[i] += 1T1[i + N] += 1T1[i + 2 * N] += 1else:T2[i] += 1T2[i + N] += 1T2[i + 2 * N] += 1for i in range(3 * N):Ac1[i + 1] = Ac1[i] + T1[i]Ac2[i + 1] = Ac2[i] + T2[i]def BinarySearch(check, yes = 10 ** 18, no = -1):while abs(yes - no) != 1:mid = (yes + no)//2if check(mid):yes = midelse:no = midreturn yesdef check1(m):return (H - h * m) > 0 and (W - w * m) > 0def check2(r):x = Ac1[r] - Ac1[P]y = Ac2[r] - Ac2[P]return H - x <= 0 or W - y <= 0for _ in range(Q):H, W, P = map(int, input().split())m = BinarySearch(check1, 0, 10 ** 9 + 5)H -= m * hW -= m * wprint(BinarySearch(check2, 3 * N, P)%N)