結果
| 問題 |
No.8081 HQ9+
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-01 23:00:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 541 bytes |
| コンパイル時間 | 1,780 ms |
| コンパイル使用メモリ | 169,080 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-21 07:04:10 |
| 合計ジャッジ時間 | 2,623 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int N;
string S;
int my_sqrt(int N){
int a=0;
while(a*a<N)a++;
return a;
}
int main(){
cin>>N>>S;
int Q=count(S.begin(),S.end(),'Q');
if(Q==0)return puts("-1"),0;
int q=my_sqrt(Q);
if(q*q!=Q)return puts("-1"),0;
if(N%q)return puts("-1"),0;
for(int i=0;i<N/q;i++){
for(int j=0;j<q;j++){
if(S[i]!=S[i+j*(N/q)])return puts("-1"),0;
}
}
if(count(S.begin(),S.end(),'H'))return puts("-1"),0;
cout<<S.substr(0,N/q)<<endl;
}