結果
問題 | No.1803 Remainder of Sum |
ユーザー |
![]() |
提出日時 | 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 = 1000000007eps = 10**-9def main():import sysfrom itertools import permutationsinput = sys.stdin.readlinedef guchoku(N, M):res = float("inf")for P in permutations(list(range(1, N+1))):A = list(range(1, N+1))ans = 0for p in P[:-1]:tmp = Mfor a in A:if a == p:continuetmp = min(tmp, (a + p) % M)ans += tmpA.remove(p)res = min(res, ans)return resfor _ in range(int(input())):N, M = map(int, input().split())if M == 1:print(0)continueif 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 - 1if 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()