結果
| 問題 |
No.2226 Hello, Forgotten World!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-24 22:25:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,308 bytes |
| コンパイル時間 | 2,166 ms |
| コンパイル使用メモリ | 197,272 KB |
| 最終ジャッジ日時 | 2025-02-10 21:28:46 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 9 |
ソースコード
#include <cctype>
#ifndef SHO_LOCAL
#include <bits/stdc++.h>
#define debug(...) ;
#else
#include "debug.h"
#endif
#define all(x) (x).begin(), (x).end()
#define lb(x, a) lower_bound(all(x), (a)) - (x).begin()
typedef long long ll;
using namespace std;
static inline vector<int> z_algo(const string &s) {
int n = (int)s.size();
vector<int> Z(n);
int from = -1, until = -1;
for (int i = 1; i < n; i++) {
int &a = Z[i];
if (from != -1) {
a = max(0, min(Z[i - from], until - i));
}
while (i + a < n && (s[i + a] == s[a] || s[a] == '?' || s[i + a] == '?')) {
a++;
}
if (until < i + a) {
until = i + a;
from = i;
}
}
Z[0] = n;
return Z;
}
static inline vector<int> z_algo2(const string &s) {
int n = (int)s.size();
vector<int> Z(n);
int from = -1, until = -1;
for (int i = 1; i < n; i++) {
int &a = Z[i];
if (from != -1) {
a = max(0, min(Z[i - from], until - i));
}
while (i + a < n && (s[i + a] == s[a] || s[i + a] == '?' || s[a] == '?')) {
a++;
}
if (until < i + a) {
until = i + a;
from = i;
}
}
Z[0] = n;
return Z;
}
int main() {
iostream::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
int n;
string s;
const string S = "helloworld$";
while (T--) {
cin >> n >> s;
string t = S + s;
auto Z = z_algo(t);
bool ok = false;
for (int i = Z.size() - 1; i >= (int)S.size(); i--) {
if (Z[i] >= 10) {
ok = true;
for (int j = 0; j < i; j++) {
if (t[j] == '?' || (t[j] >= 'A' && t[j] <= 'Z'))
t[j] = 'A';
}
for (int j = 0; j < 10; j++) {
if (t[i + j] == '?' || (t[i + j] >= 'A' && t[i + j] <= 'Z')) {
if (t[i + j] == '?') {
t[i + j] = 'z' + 1;
}
t[i + j] = min(char(S[j] - 'a' + 'A'), t[i + j]);
}
}
for (int j = i + 10; j < (int)Z.size(); j++) {
if (t[j] == '?' || (t[j] >= 'A' && t[j] <= 'Z'))
t[j] = 'A';
}
string ans = t.substr(S.size());
for (char &c : ans) {
if ('A' <= c && c <= 'Z') {
c = c - 'A' + 'a';
}
}
cout << ans << '\n';
}
}
if (!ok)
cout << -1 << '\n';
}
return 0;
}