結果

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

ソースコード

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;
  }
  
  if (count == 0) {
    cout << -1 << '\n';
    return 0;
  }
  
  string t = "";
  for (int i = 0; i < n / 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