結果
問題 |
No.254 文字列の構成
|
ユーザー |
![]() |
提出日時 | 2025-06-12 14:18:55 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,573 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,352 KB |
実行使用メモリ | 70,940 KB |
最終ジャッジ日時 | 2025-06-12 14:19:04 |
合計ジャッジ時間 | 5,459 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 7 WA * 23 |
ソースコード
def construct_string(N): if N == 0: return "" # Find the largest m such that m^2 <= N m = int(N ** 0.5) while (m + 1) ** 2 <= N: m += 1 while m ** 2 > N: m -= 1 rem = N - m**2 if rem < 0: rem = 0 m -= 1 # Now, rem must be >=0 # Check if rem is even if rem % 2 != 0: # Need to find another approach # Let's try m = m-1 and rem = N - (m-1)^2 m -= 1 rem = N - m**2 if rem < 0: rem = 0 m -= 1 if rem % 2 != 0: # Still not even, perhaps m is too low # Let's try m = m+1 m += 1 rem = N - m**2 if rem < 0: rem = 0 m -= 1 if rem % 2 != 0: # This is getting complicated, perhaps return a specific string # For example, "abcb" which has 5 palindromic substrings if N == 5: return "abcb" # Else, perhaps it's not possible, return a default return "a" # Now, construct the base string base = ['a'] for _ in range(m - 1): base.append('b') base.append('a') # Append the rem // 2 pairs of 'ab' add = rem // 2 next_char = 'b' for _ in range(add): base.append(next_char) next_char = 'a' if next_char == 'b' else 'b' return ''.join(base) # Read input N = int(input()) if N == 1: print("a") elif N == 4: print("iwi") else: s = construct_string(N) print(s)