結果
| 問題 | No.3795 Circular railway |
| ユーザー |
|
| 提出日時 | 2026-11-13 22:33:04 |
| 言語 | PyPy3 (8.0.1 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 619 ms / 2,000 ms |
| + 867µs | |
| コード長 | 1,318 bytes |
| 記録 | |
| コンパイル時間 | 79 ms |
| コンパイル使用メモリ | 64,384 KB |
| 実行使用メモリ | 63,104 KB |
| 最終ジャッジ日時 | 2026-11-13 22:33:24 |
| 合計ジャッジ時間 | 8,729 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
import sys
sys.setrecursionlimit(10**7)
#↓codon===============================
import string
Alp_low=list(string.ascii_lowercase)
Alp_up=list(string.ascii_uppercase)
Digit="0123456789"
dij=[[0,1],[1,0],[0,-1],[-1,0]]
def nin():
"""
library
https://github.com/not522/ac-library-python
https://github.com/cheran-senthil/PyRival
https://github.com/kurao2924/Kurao_Py_Library
https://github.com/navel-tos/cp-library-for-codon
"""
return list(map(int,input().split()))
def deq(x):
return [i-1 for i in x]
mod=998244353
_factorial=[1]
def factorial(n):
while len(_factorial)<=n:
_factorial.append((_factorial[-1]*len(_factorial))%mod)
return _factorial[n]
_inv_factorial=[1]
def inv_factorial(n):
while len(_inv_factorial)<=n:
_inv_factorial.append((_inv_factorial[-1]*pow(len(_inv_factorial),mod-2,mod))%mod)
return _inv_factorial[n]
def binom(n,r):
if r>=mod:
raise ValueError("r is too big")
if n<0:
return 0
if r>n:
return 0
if r<0:
return 0
ans=((factorial(n)*inv_factorial(r))%mod*inv_factorial(n-r))%mod
return ans
mod=998244353
def main():
n,q,s,t,c=nin()
s-=1
t-=1
for _ in range(q):
u,v=deq(nin())
print(min((v-u)%n,(s-u)%n+(v-t)%n+c))
if __name__=="__main__":
main()