結果

問題 No.2716 Falcon Method
ユーザー mkawa2mkawa2
提出日時 2024-04-05 21:54:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 307 ms / 2,000 ms
コード長 1,343 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 80,392 KB
最終ジャッジ日時 2024-04-05 21:54:59
合計ジャッジ時間 6,560 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 40 ms
53,460 KB
testcase_03 AC 40 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 61 ms
68,440 KB
testcase_07 AC 67 ms
72,584 KB
testcase_08 AC 67 ms
70,524 KB
testcase_09 AC 69 ms
72,600 KB
testcase_10 AC 60 ms
68,444 KB
testcase_11 AC 289 ms
80,028 KB
testcase_12 AC 230 ms
79,644 KB
testcase_13 AC 201 ms
79,700 KB
testcase_14 AC 248 ms
79,256 KB
testcase_15 AC 250 ms
79,784 KB
testcase_16 AC 262 ms
79,544 KB
testcase_17 AC 291 ms
79,640 KB
testcase_18 AC 307 ms
79,768 KB
testcase_19 AC 274 ms
79,216 KB
testcase_20 AC 211 ms
79,740 KB
testcase_21 AC 236 ms
79,708 KB
testcase_22 AC 261 ms
80,392 KB
testcase_23 AC 284 ms
79,956 KB
testcase_24 AC 297 ms
80,364 KB
testcase_25 AC 37 ms
53,460 KB
testcase_26 AC 36 ms
53,460 KB
testcase_27 AC 277 ms
80,072 KB
testcase_28 AC 280 ms
80,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

n,q=LI()
a=[0]*(n+1)
b=[0]*(n+1)
for i,c in enumerate(SI()):
    if c=="D":a[i+1]=1
    else:b[i+1]=1

for i in range(n):
    a[i+1]+=a[i]
    b[i+1]+=b[i]

def binary_search(l, r, minimize):
    if minimize: l -= 1
    else: r += 1
    while l+1 < r:
        m = (l+r)//2
        if ok(m) ^ minimize: l = m
        else: r = m
    if minimize: return r
    return l

def ok(m):
    t,r=divmod(m,n)
    i=a[-1]*t+a[r]-a[p]
    j=b[-1]*t+b[r]-b[p]
    # print(m,i,j)
    return i>=h or j>=w

for _ in range(q):
    h,w,p=LI()
    c=binary_search(p,3*10**9,True)
    print(c%n)
0