結果

問題 No.2226 Hello, Forgotten World!
ユーザー norikamenorikame
提出日時 2022-12-14 02:00:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 199,808 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-07 02:39:37
合計ジャッジ時間 2,799 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// 

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

const string tar = "helloworld";

int main() {
    int t0;
    cin >> t0;
    rep(i0, t0) {
        int n;
        string s;
        cin >> n >> s;
        int tlen = tar.length();
        string res = "";
        for (int i=0; i+tlen-1<n; ++i) {
            bool ok = true;
            rep(j, tlen) if (s[i+j]!='?' && s[i+j]!=tar[j]) {
                ok = false;
                break;
            }
            if (!ok) continue;
            string ts = s;
            rep(j, tlen) ts[i+j] = tar[j];
            rep(j, n) if (ts[j] == '?') ts[j] = 'a';
            if (res.empty()) res = ts;
            else res = min(res, ts);
        }
        if (res.empty()) cout << -1 << endl;
        else cout << res << endl;
    }
    return 0;
}
0