結果
問題 | No.8081 HQ9+ |
ユーザー |
|
提出日時 | 2023-09-15 17:28:58 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 873 bytes |
コンパイル時間 | 3,071 ms |
コンパイル使用メモリ | 248,228 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-02 19:38:45 |
合計ジャッジ時間 | 3,810 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 RE * 1 |
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 (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; }