結果
| 問題 |
No.1730 GCD on Blackboard in yukicoder
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 16:13:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 249 ms / 2,000 ms |
| コード長 | 1,264 bytes |
| コンパイル時間 | 394 ms |
| コンパイル使用メモリ | 81,832 KB |
| 実行使用メモリ | 148,944 KB |
| 最終ジャッジ日時 | 2025-04-16 16:18:07 |
| 合計ジャッジ時間 | 6,116 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 |
ソースコード
def main():
import sys
input = sys.stdin.read
data = input().split()
N = int(data[0])
A = list(map(int, data[1:N+1]))
max_A = max(A)
freq = [0] * (max_A + 1)
for a in A:
freq[a] += 1
# Compute count[d] for all d from 1 to max_A
count = [0] * (max_A + 1)
for d in range(1, max_A + 1):
for multiple in range(d, max_A + 1, d):
count[d] += freq[multiple]
# Collect all d with count[d] > 0 and sort in descending order
sorted_d = [d for d in range(1, max_A + 1) if count[d] > 0]
sorted_d.sort(reverse=True)
max_d = [0] * (N + 2) # max_d[t] for t from 0 to N
filled_t = 0
for d in sorted_d:
current_max_t = min(count[d], N)
if current_max_t <= filled_t:
continue
start = filled_t + 1
end = current_max_t
if start > end:
continue
for t in range(start, end + 1):
max_d[t] = d
filled_t = end
if filled_t >= N:
break
# Generate output for each K from 0 to N-1
output = []
for K in range(N):
t = N - K
output.append(str(max_d[t]))
print('\n'.join(output))
if __name__ == "__main__":
main()
lam6er