結果
問題 | No.2947 Sing a Song |
ユーザー |
|
提出日時 | 2024-10-25 22:07:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 1,219 bytes |
コンパイル時間 | 253 ms |
コンパイル使用メモリ | 82,500 KB |
実行使用メモリ | 80,552 KB |
最終ジャッジ日時 | 2024-10-25 22:07:45 |
合計ジャッジ時間 | 4,384 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
def create_song(N, S, T, A): lyrics = [] for notes in A: segment = [] # Sの使用回数を最大化 count_S = notes // len(S) remaining_notes = notes % len(S) # Sの使用回数を調整して、Tを使用できるようにする while remaining_notes % len(T) != 0 and count_S > 0: count_S -= 1 remaining_notes += len(S) # Sの歌詞を追加 if count_S > 0: segment.append(S * count_S) # Tの使用回数を計算 count_T = remaining_notes // len(T) if count_T > 0: segment.append(T * count_T) # 空白でつなげる final_segment = [] # SとTの音を交互に追加し、空白で区切る if count_S > 0: final_segment.extend([S] * count_S) if count_T > 0: final_segment.extend([T] * count_T) # すべての音の間に空白を入れる lyrics.append(' '.join(final_segment)) # 結果を出力 print('\n'.join(lyrics)) # 入力処理 N = int(input()) S, T = input().split() A = list(map(int, input().split())) # 歌詞を作成 create_song(N, S, T, A)