結果
問題 |
No.2716 Falcon Method
|
ユーザー |
|
提出日時 | 2025-06-10 07:53:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 995 ms / 2,000 ms |
コード長 | 2,043 bytes |
コンパイル時間 | 613 ms |
コンパイル使用メモリ | 82,792 KB |
実行使用メモリ | 135,096 KB |
最終ジャッジ日時 | 2025-06-10 07:53:58 |
合計ジャッジ時間 | 17,148 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
from collections import Counter, deque, defaultdict from heapq import heapify, heappop, heappush, nlargest, nsmallest from bisect import bisect_left, bisect, bisect_right from copy import deepcopy from time import perf_counter import sys from typing import Any, List, Callable def debug(*args, sep=" ", end="\n") -> None: print(*args, sep=sep, end=end, file=sys.stderr) class function_wrapper: def __init__(self, f) -> None: self.f = f def __getitem__(self, x): return self.f(x) def functional_bisect_right(f, x, hi, lo=0): fw = function_wrapper(f) return bisect_right(fw, x, lo, hi) def functional_bisect_left(f, x, hi, lo=0): fw = function_wrapper(f) return bisect_left(fw, x, lo, hi) def main(): global inf, MOD input = sys.stdin.read().split() ptr = 0 inf = float("inf") MOD = 998244353 N, Q = map(int, input[ptr:ptr + 2]); ptr += 2 S = input[ptr]; ptr += 1 A = [[0, 0] for _ in range(N + 1)] for i in range(N): A[i + 1] = A[i][:] if S[i] == 'D': A[i + 1][0] += 1 else: A[i + 1][1] += 1 X, Y = A[-1] def solve(x, c, p, m): if x + p < N: res = int(A[x + p][c] - A[p][c] >= m) else: res = int(A[-1][c] - (A[p][c] - A[x + p - N][c]) >= m) return res for _ in range(Q): h, w, p = map(int, input[ptr:ptr + 3]); ptr += 3 k = min(h // X if X > 0 else inf, w // Y if Y > 0 else inf) h -= k * X; w -= k * Y if h == 0: i = functional_bisect_right(f=lambda x: solve(x, 0, p, X), x=0, hi=N, lo=0) - N else: i = functional_bisect_right(f=lambda x: solve(x, 0, p, h), x=0, hi=N, lo=0) if w == 0: j = functional_bisect_right(f=lambda x: solve(x, 1, p, Y), x=0, hi=N, lo=0) - N else: j = functional_bisect_right(f=lambda x: solve(x, 1, p, w), x=0, hi=N, lo=0) i = min(i, j) print((p + i) % N) if __name__ == "__main__": main()