結果
問題 |
No.3158 Collect Stamps
|
ユーザー |
![]() |
提出日時 | 2025-05-23 21:17:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 319 ms / 2,000 ms |
コード長 | 1,707 bytes |
コンパイル時間 | 264 ms |
コンパイル使用メモリ | 82,780 KB |
実行使用メモリ | 76,776 KB |
最終ジャッジ日時 | 2025-05-23 21:18:00 |
合計ジャッジ時間 | 4,956 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#yukicoder 3155- KCPC新歓杯 ''' #3155 import random N = int(input()) birthday = [tuple(map(int, input().split())) for _ in range(N)] birthday.sort() print('Yes' if any(birthday[i] == birthday[i + 1] for i in range(N - 1)) else 'No') #3156 K, N = map(int, input().split()) ans = [] for x in range(1, N + 1): if (x6 := x ** 6) > N: break for y in range(1, N + 1): if x6 + (y4 := y ** 4) > N: break if (n := x6 + y4) < K: continue z2 = n // K if K * z2 != n: continue z = max(0, int(z2 ** 0.5) - 2) while z ** 2 < z2: z += 1 if z ** 2 != z2: continue ans.append(n) ans.sort() cnt = 0 if len(ans) == 0 else 1 for i in range(1, len(ans)): if ans[i - 1] != ans[i]: cnt += 1 print(cnt) #3157 N = [int(Si) for Si in input().rstrip()] while True: #最上位の3を検知し、繰り下がりで消す for i in range( len(N) ): if N[i] == 3: N[i] = 2 for j in range(i + 1, len(N)):N[j] = 9 break if sum(N) % 3 == 0: N[-1] -= 1 for i in range( len(N) - 1, -1, -1 ): if N[i] < 0: N[i - 1] -= 1 N[i] += 10 else: break print(''.join([str(Si) for Si in N])) ''' #3158 N, M, K = map(int, input().split()) A = list(map(lambda x: int(x) - 1, input().split())) T = [tuple(map(int, input().split())) for _ in range(N)] #TSPするの・・・? → M <= 5なのでpermutationsで大丈夫そう import itertools ans = ~ ( - 1 << 63) for S in itertools.permutations( range(N), r = M ): dist = sum(T[ S[i] ][ S[i + 1] ] for i in range(M - 1)) for Ai in A: ans = min( ans, dist + T[ S[-1] ][Ai] ) print(ans)