結果

問題 No.2226 Hello, Forgotten World!
ユーザー tsugutsugutsugutsugu
提出日時 2023-02-24 21:42:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 2,034 ms
コンパイル使用メモリ 175,272 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-11 06:00:31
合計ジャッジ時間 2,534 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

string x = "helloworld";

void solve() {
    int n;
    string s;
    cin >> n >> s;
    vector<string> can;
    for (int i = n - (int) x.size(); i >= 0; i--) {
        string t = s;
        bool ok = true;
        for (int j = 0; j < (int) x.size(); j++) {
            if (t[i + j] != '?' && t[i + j] != x[j]) {
                ok = false;
                break;
            } else {
                t[i + j] = x[j];
            }
        }
        if (ok) {
            for (auto&& c : t) {
                if (c == '?') {
                    c = 'a';
                }
            }
            can.push_back(t); 
        }
    }
    if (can.size()) {
        sort(can.begin(), can.end());
        cout << can[0] << endl;
        return;
    } else {
        cout << -1 << endl;
        return;
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
0