結果
| 問題 |
No.8081 HQ9+
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-03-09 15:43:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 2,000 ms |
| コード長 | 682 bytes |
| コンパイル時間 | 573 ms |
| コンパイル使用メモリ | 66,176 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-12 08:46:42 |
| 合計ジャッジ時間 | 1,622 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
#include<iostream>
using namespace std;
int N;
string S;
int main()
{
cin>>N>>S;
if(!(1<=N&&N<=100000))
{
cerr<<"N range error"<<endl;
return 1;
}
if(N!=S.size())
{
cout<<"N not equal to |S|"<<endl;
return 1;
}
for(char c:S)
{
if(!('a'<=c&&c<='z'||'A'<=c&&c<='Z'))
{
cout<<"S contains non-alphabetic character"<<endl;
return 1;
}
}
for(int c=1;c<=N;c++)if(N%c==0)
{
string T=S.substr(0,N/c);
bool ok=true;
int Qc=0;
for(char t:T)
{
if(t=='Q')Qc++;
if(t=='H')ok=false;
}
if(Qc!=c)ok=false;
for(int i=0;i<c;i++)if(T!=S.substr(i*(N/c),N/c))ok=false;
if(ok)
{
cout<<T<<endl;
return 0;
}
}
cout<<-1<<endl;
return 0;
}