結果

問題 No.2259 Gas Station
ユーザー ShirotsumeShirotsume
提出日時 2023-04-07 21:28:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,234 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 55,452 KB
最終ジャッジ日時 2024-04-10 16:36:41
合計ジャッジ時間 2,030 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,308 KB
testcase_01 AC 38 ms
55,364 KB
testcase_02 AC 39 ms
54,568 KB
testcase_03 AC 37 ms
54,400 KB
testcase_04 AC 38 ms
54,928 KB
testcase_05 AC 39 ms
54,408 KB
testcase_06 AC 40 ms
55,452 KB
testcase_07 AC 39 ms
55,356 KB
testcase_08 AC 38 ms
54,124 KB
testcase_09 AC 39 ms
54,648 KB
testcase_10 AC 39 ms
54,468 KB
testcase_11 AC 38 ms
53,924 KB
testcase_12 AC 39 ms
55,008 KB
testcase_13 AC 39 ms
54,720 KB
testcase_14 AC 39 ms
54,276 KB
testcase_15 AC 39 ms
55,252 KB
testcase_16 AC 40 ms
54,192 KB
testcase_17 AC 39 ms
55,192 KB
testcase_18 AC 39 ms
54,388 KB
testcase_19 AC 38 ms
55,004 KB
testcase_20 AC 38 ms
54,540 KB
testcase_21 AC 38 ms
54,656 KB
testcase_22 AC 38 ms
54,792 KB
testcase_23 AC 38 ms
55,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque, Counter
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
import sys
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
mod = 998244353
def floor_sum(n,m,a,b):
    ans=0
    if a>=m:
        ans+=(n-1)*n*(a//m)//2
        a%=m
    if b>=m:
        ans+=n*(b//m)
        b%=m
    y_max=(a*n+b)//m
    x_max=(y_max*m-b)
    if y_max==0:
        return ans
    ans+=(n-(x_max+a-1)//a)*y_max
    ans+=floor_sum(y_max,a,m,(a-x_max%a)%a)
    return ans

def mod_le(n, a, b, k, m):
    #0 <= x < n について、 (a * x + b) mod m < k なるものの個数を求める
    return floor_sum(n, m, a, b + m) - floor_sum(n, m, a, b - k + m)


for _ in range(1):
    l, r, c = mi()
    n = r - l + 1
    m = 1000
    a = (- c) % m
    b = (1000 - l * c) % m
    if a == 0:
        print(b % m)
        continue
    ok = m
    ng = 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if mod_le(n, a, b, mid, m):
            ok = mid
        else:
            ng = mid
    print(ok - 1)
0