結果
問題 | No.1803 Remainder of Sum |
ユーザー | tamato |
提出日時 | 2022-01-07 23:08:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 124 ms / 2,000 ms |
コード長 | 1,177 bytes |
コンパイル時間 | 180 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 76,800 KB |
最終ジャッジ日時 | 2024-04-26 18:59:34 |
合計ジャッジ時間 | 2,243 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,096 KB |
testcase_01 | AC | 115 ms
76,416 KB |
testcase_02 | AC | 114 ms
76,672 KB |
testcase_03 | AC | 115 ms
76,544 KB |
testcase_04 | AC | 123 ms
76,416 KB |
testcase_05 | AC | 119 ms
76,416 KB |
testcase_06 | AC | 115 ms
76,288 KB |
testcase_07 | AC | 104 ms
76,672 KB |
testcase_08 | AC | 124 ms
76,800 KB |
ソースコード
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()