結果
問題 |
No.501 穴と文字列
|
ユーザー |
![]() |
提出日時 | 2025-03-20 18:41:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 910 bytes |
コンパイル時間 | 235 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 72,188 KB |
最終ジャッジ日時 | 2025-03-20 18:41:40 |
合計ジャッジ時間 | 1,898 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
# Read input N, D = map(int, input().split()) # Initialize hole counts for each character hole = [0] * 26 # Index 0 for 'A', 1 for 'B', ..., 25 for 'Z' # Set holes for 'B' hole[ord('B') - ord('A')] = 2 # Set holes for characters with 1 hole for c in ['A', 'D', 'O', 'P', 'Q', 'R']: hole[ord(c) - ord('A')] = 1 result = [] current_sum = 0 for i in range(N): m = N - i - 1 # Remaining characters after current # Iterate through each character from 'A' to 'Z' for c_ord in range(ord('A'), ord('Z') + 1): c = chr(c_ord) k = hole[c_ord - ord('A')] new_sum = current_sum + k required = D - new_sum if required < 0: continue # Check if remaining required holes can be achieved with m characters if 0 <= required <= 2 * m: result.append(c) current_sum = new_sum break print(''.join(result))