結果
| 問題 |
No.2226 Hello, Forgotten World!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-24 21:57:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 17 ms / 2,000 ms |
| コード長 | 1,153 bytes |
| コンパイル時間 | 1,986 ms |
| コンパイル使用メモリ | 196,516 KB |
| 最終ジャッジ日時 | 2025-02-10 21:01:51 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const string key = "helloworld";
bool OK(string& s, int j) {
for (int i = 0; i < 10; i ++) {
if (s[i + j] != key[i] && s[i + j] != '?') {
return false;
}
}
for (int i = 0; i < 10; i ++) {
s[i + j] = key[i];
}
return true;
}
void solve() {
int N;
string s;
cin >> N >> s;
if (N < 10) {
cout << -1 << endl;
return;
}
string ret = "{-1";
for (int i = 0; i <= N - 10; i ++) {
if (s.substr(i, 10) == key) {
ret = s;
for (auto& c : ret) {
c = (c == '?' ? 'a' : c);
}
break;
}
}
string ss = s;
for (int i = N - 10; i >= 0; i --) {
ss = s;
if (OK(ss, i)) {
for (auto& c : ss) {
c = (c == '?' ? 'a' : c);
}
ret = min(ret, ss);
}
}
if (ret[0] == '{') {
cout << -1 << endl;
} else {
cout << ret << endl;
}
return;
}
int main () {
int N;
cin >> N;
for (int i = 0; i < N; i ++) {
solve();
}
}