結果
| 問題 | 
                            No.8081 HQ9+
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-04-01 21:59:09 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 478 bytes | 
| コンパイル時間 | 1,731 ms | 
| コンパイル使用メモリ | 168,128 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-12-21 06:17:46 | 
| 合計ジャッジ時間 | 2,335 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 15 WA * 6 | 
ソースコード
#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;
        }
    }
    cout<<S.substr(0,N/q);
}