結果

問題 No.2716 Falcon Method
ユーザー ShirotsumeShirotsume
提出日時 2024-04-05 21:58:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,649 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 83,760 KB
最終ジャッジ日時 2024-04-05 21:58:12
合計ジャッジ時間 6,122 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
56,152 KB
testcase_01 AC 46 ms
56,152 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 43 ms
56,152 KB
testcase_06 AC 86 ms
77,204 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 87 ms
77,084 KB
testcase_11 AC 245 ms
83,152 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 231 ms
82,424 KB
testcase_22 AC 235 ms
83,492 KB
testcase_23 AC 254 ms
83,760 KB
testcase_24 AC 253 ms
83,740 KB
testcase_25 AC 43 ms
56,152 KB
testcase_26 AC 46 ms
56,152 KB
testcase_27 AC 216 ms
83,732 KB
testcase_28 AC 226 ms
83,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 61 - 1
mod = 998244353
class Cumsum1d():
    def __init__(self, A):
        self.n = len(A)
        self.Suma = [0] * (self.n + 1)
        for i in range(self.n):
            self.Suma[i + 1] += self.Suma[i] + A[i]

    def query(self, l, r):
        #0-indexed
        return self.Suma[r] - self.Suma[l]

    def get(self, i):
        return self.Suma[i + 1] - self.Suma[i]

    def __getitem__(self, p):
        if isinstance(p, int):
            return self.get(p)
        else:
            return self.query(p.start, p.stop)
n, q = mi()
s = input()

R = [0] * n
D = [0] * n
for i in range(n):
    if s[i] == 'R':
        R[i] = 1
    else:
        D[i] = 1
R = Cumsum1d(R)
D = Cumsum1d(D)
def countr(p, d):
    #p項目からd項にわたるrの個数
    ret = 0
    if n - p <= d:
        ret += R.query(p, n)
        d -= n - p
    ret += (d // n) * R.query(0, n)
    ret += R.query(0, d % n)
    return ret
def countd(p, d):
    #p項目からd項にわたるdの個数
    ret = 0
    if n - p <= d:
        ret += D.query(p, n)
        d -= n - p
    ret += (d // n) * D.query(0, n)
    ret += D.query(0, d % n)
    return ret

for i in range(q):
    h, w, p = mi()
    ok = h + w
    ng = 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        r = countr(p, mid)
        d = countd(p, mid)
        if d >= h or r >= w:
            ok = mid
        else:
            ng = mid
    print((p + ok) % n)
    
0