結果
| 問題 |
No.8081 HQ9+
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-15 17:29:56 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 883 bytes |
| コンパイル時間 | 2,990 ms |
| コンパイル使用メモリ | 248,092 KB |
| 実行使用メモリ | 6,940 KB |
| 最終ジャッジ日時 | 2024-07-02 19:39:37 |
| 合計ジャッジ時間 | 3,885 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 WA * 3 |
ソースコード
#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, (i + 1) * n / m)) {
cout << -1 << endl;
return 0;
}
}
cout << s.substr(0, n / m) << endl;
return 0;
}