結果

問題 No.2226 Hello, Forgotten World!
ユーザー publfl2publfl2
提出日時 2023-02-24 21:44:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,418 bytes
コンパイル時間 394 ms
コンパイル使用メモリ 50,404 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 06:01:59
合計ジャッジ時間 1,161 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 34 ms
4,352 KB
testcase_02 AC 7 ms
4,348 KB
testcase_03 AC 6 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 6 ms
4,352 KB
testcase_06 AC 3 ms
4,352 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <string.h>
char x[1010],y[1010]="helloworld";
int func(int k, int mode)
{
	if(mode==0)
	{
		for(int i=k;i<=k+9;i++) if(x[i]!=y[i-k]) return 0;
		return 1;
	}
	else
	{
		for(int i=k;i<=k+9;i++) if(x[i]!=y[i-k] && x[i]!='?') return 0;
		return 1;
	}
}

std::vector<char> ans,V;
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		ans.clear();
		int a;
		scanf("%d",&a);
		scanf("%s",x+1);
		for(int i=1;i+9<=a;i++)
		{
			if(func(i,0))
			{
				for(int j=1;j<=a;j++) if(x[j]=='?') x[j] = 'a';
				for(int j=1;j<=a;j++) printf("%c",x[j]);
				printf("\n");
				goto u;
			}
		}
		
		for(int i=1;i+9<=a;i++)
		{
			if(func(i,1))
			{
				V.clear();
				for(int j=1;j<i;j++)
				{
					if(x[j]=='?') V.push_back('a');
					else V.push_back(x[j]);
				}
				for(int j=i;j<=i+9;j++) V.push_back(y[j-i]);
				for(int j=i+10;j<=a;j++)
				{
					if(x[j]=='?') V.push_back('a');
					else V.push_back(x[j]);
				}
				
				if(ans.empty())
				{
					for(int j=0;j<V.size();j++) ans.push_back(V[j]);
				}
				else
				{
					for(int j=0;j<V.size();j++)
					{
						if(V[j]<ans[j])
						{
							ans.clear();
							for(int j=0;j<V.size();j++) ans.push_back(V[j]);
							break;
						}
						else if(V[j]>ans[j]) break;
					}
				}
			}
		}
		if(ans.size()==0) printf("-1\n");
		else
		{
			for(int j=0;j<ans.size();j++) printf("%c",ans[j]);
			printf("\n");
		}
		
		u:;
	}
}
0