結果
| 問題 |
No.1803 Remainder of Sum
|
| コンテスト | |
| ユーザー |
tamato
|
| 提出日時 | 2022-01-07 23:08:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 114 ms / 2,000 ms |
| コード長 | 1,177 bytes |
| コンパイル時間 | 154 ms |
| コンパイル使用メモリ | 82,380 KB |
| 実行使用メモリ | 76,788 KB |
| 最終ジャッジ日時 | 2024-11-14 09:09:50 |
| 合計ジャッジ時間 | 2,196 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
ソースコード
mod = 1000000007
eps = 10**-9
def main():
import sys
from itertools import permutations
input = sys.stdin.readline
def guchoku(N, M):
res = float("inf")
for P in permutations(list(range(1, N+1))):
A = list(range(1, N+1))
ans = 0
for p in P[:-1]:
tmp = M
for a in A:
if a == p:
continue
tmp = min(tmp, (a + p) % M)
ans += tmp
A.remove(p)
res = min(res, ans)
return res
for _ in range(int(input())):
N, M = map(int, input().split())
if M == 1:
print(0)
continue
if M <= N:
if M == 2:
print(1)
else:
print(M // 2)
elif M >= 2 * N:
print(N - 1 + (N * (N + 1)) // 2 - 1)
else:
K = M - N - 1
if K == 0:
print((N - 1) // 2)
else:
print((N - K - 1) // 2 + K + ((K + 1) * (K + 2)) // 2 - 1)
#print(guchoku(N, M))
if __name__ == '__main__':
main()
tamato