結果

問題 No.2226 Hello, Forgotten World!
ユーザー norikamenorikame
提出日時 2022-12-14 00:59:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,498 bytes
コンパイル時間 2,671 ms
コンパイル使用メモリ 210,132 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 02:39:34
合計ジャッジ時間 3,535 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 11 ms
4,384 KB
testcase_02 AC 4 ms
4,384 KB
testcase_03 AC 4 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 3 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 3 ms
4,384 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;
        bool exist = false;
        int tlen = tar.length();
        for (int i=0; i+tlen-1<n; ++i) if (s.substr(i, tlen) == tar) {
            exist = true;
            break;
        }
        if (exist) {
            rep(i, n) if (s[i] == '?') s[i] = 'a';
            cout << s << endl;
        }
        else {
            vector<string> slst;
            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) {
                    auto ts = s;
                    rep(j, tlen) ts[i+j] = tar[j];
                    rep(j, n) if (ts[j] == '?') ts[j] = 'a';
                    slst.push_back(ts);
                }
            }
            if (!slst.empty()) {
                sort(all(slst));
                cout << slst[0] << endl;
            }
            else cout << -1 << endl;
        }
    }
    return 0;
}
0