結果

問題 No.3081 HQ9+
ユーザー kotatsugamekotatsugame
提出日時 2021-03-09 15:43:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 66,500 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-02 13:13:53
合計ジャッジ時間 2,054 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0