結果
問題 | No.3081 HQ9+ |
ユーザー | 大玖すとら |
提出日時 | 2021-04-01 21:45:29 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 585 bytes |
コンパイル時間 | 578 ms |
コンパイル使用メモリ | 87,120 KB |
実行使用メモリ | 75,896 KB |
最終ジャッジ日時 | 2023-08-23 05:50:35 |
合計ジャッジ時間 | 3,260 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 68 ms
71,372 KB |
testcase_01 | AC | 69 ms
71,448 KB |
testcase_02 | AC | 68 ms
71,120 KB |
testcase_03 | AC | 69 ms
71,264 KB |
testcase_04 | AC | 68 ms
71,332 KB |
testcase_05 | AC | 71 ms
71,552 KB |
testcase_06 | AC | 69 ms
71,436 KB |
testcase_07 | AC | 71 ms
71,436 KB |
testcase_08 | AC | 69 ms
71,520 KB |
testcase_09 | AC | 70 ms
71,408 KB |
testcase_10 | AC | 69 ms
71,180 KB |
testcase_11 | AC | 70 ms
71,440 KB |
testcase_12 | AC | 70 ms
71,408 KB |
testcase_13 | AC | 70 ms
71,332 KB |
testcase_14 | AC | 74 ms
75,896 KB |
testcase_15 | AC | 71 ms
71,404 KB |
testcase_16 | AC | 73 ms
75,784 KB |
testcase_17 | AC | 72 ms
71,408 KB |
testcase_18 | AC | 70 ms
71,324 KB |
testcase_19 | AC | 69 ms
71,440 KB |
testcase_20 | AC | 69 ms
71,668 KB |
testcase_21 | AC | 70 ms
71,392 KB |
testcase_22 | AC | 70 ms
71,524 KB |
ソースコード
N = int(input()) S = input() if "H" in S: print(-1) exit(0) Q = S.count("Q") if Q == 1: print(S) exit(0) qsqrt = 0 for x in range(1, N): if x ** 2 == Q: qsqrt = x break else: print(-1) exit(0) table = [0] * (N + 1) table[0] = -1 i, j = 0, 1 while j < len(S): matched = S[i] == S[j] if not matched and i > 0: i = table[i] else: if matched: i += 1 j += 1 table[j] = i length = N - table[N] substring = S[: length] substringQ = substring.count("Q") if qsqrt % substringQ: print(-1) exit(0) print(substring * (qsqrt // substringQ))