結果
問題 | No.8081 HQ9+ |
ユーザー |
|
提出日時 | 2023-09-15 17:39:57 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 873 bytes |
コンパイル時間 | 2,781 ms |
コンパイル使用メモリ | 246,536 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 19:47:30 |
合計ジャッジ時間 | 3,615 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>#define rep(i, n) for (int i = 0; i < (n); i++)using namespace std;int main() {int n;string s;cin >> n >> s;int nh = count(begin(s), end(s), 'H');int nq = count(begin(s), end(s), 'Q');if (nh > 0) {cout << -1 << endl;return 0;}// s は 'Q' をちょうど m^2 個含み, さらにある長さ n/m の文字列の m 回の繰り返しになっていないといけないint m = round(sqrt(nq));if (m * m != nq) {cout << -1 << endl;return 0;}if (m == 0 or n % m != 0) {cout << -1 << endl;return 0;}for (int i = 1; i < m; i++) {if (s.substr(0, n / m) != s.substr(i * n / m, n / m)) {cout << -1 << endl;return 0;}}cout << s.substr(0, n / m) << endl;return 0;}