結果

問題 No.8081 HQ9+
ユーザー hanyu
提出日時 2021-04-01 23:45:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 547 bytes
コンパイル時間 2,733 ms
コンパイル使用メモリ 193,976 KB
最終ジャッジ日時 2025-01-20 07:25:25
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'Q') count++;
    if (s[i] == 'H') {
      cout << -1 << '\n';
      return 0;
    }
  }
  
  if (sqrt(count) * sqrt(count) != count) {
    cout << -1 << '\n';
    return 0;
  }
  
  string t = "";
  for (int i = 0; i < sqrt(count); i++) t += s[i];
  string t2 = "";
  for (int i = 0; i < sqrt(count); i++) t2 += t;
  
  if (t2 != s) cout << -1 << '\n';
  else cout << t << '\n';
}
0