結果

問題 No.2226 Hello, Forgotten World!
ユーザー 👑 hitonanodehitonanode
提出日時 2023-02-24 23:11:19
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,152 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 81,516 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 06:51:00
合計ジャッジ時間 1,448 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

const string target = "helloworld";
string solve(string S) {
    const int N = S.size();

    string candidate;
    candidate += (char)('z' + 1);

    IREP(i, N - int(target.size()) + 1) {
        bool good = true;
        REP(j, target.size()) {
            if (S.at(i + j) == '?') continue;
            if (S.at(i + j) != target.at(j)) good = false;
        }
        if (good) {
            string T = S;
            REP(j, target.size()) T.at(i + j) = target.at(j);
            for (auto &c : T)
                if (c == '?') c = 'a';
            candidate = min(candidate, T);
        }
    }
    if (candidate.size() <= 1) return "-1";
    return candidate;
}

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
        int N;
        string S;
        cin >> N >> S;
        cout << solve(S) << '\n';
    }
}
0