結果

問題 No.2226 Hello, Forgotten World!
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-02-25 01:30:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,237 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 200,840 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 07:36:11
合計ジャッジ時間 3,320 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// 提出時にassertはオフ
#ifndef DEBUG
#ifndef NDEBUG
#define NDEBUG
#endif
#endif

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

#define ALL(x) (x).begin(), (x).end()
template <class T> using vec = vector<T>;

string solve(){
    int N;
    string S;
    cin >> N >> S;
    // 後ろからhelloworldの一致を試して、残りはaを詰め込む
    const string helloworld = "helloworld";
    const int size = helloworld.size();
    string ans = "{}";
    for(int i = N - size; i >= 0; i--){
        bool matched = true;
        for(int j = 0; j < size; j++){
            if(S[i + j] != '?' && S[i + j] != helloworld[j]) {
                matched = false;
                break;
            }
        }
        if(matched){
            string T = S;
            for(int j = 0; j < size; j++) {
                T[i + j] = helloworld[j];
            }
            for(char &x : T){
                if(x == '?') x = 'a';
            }
            if(T < ans) ans = T;
        }
    }
    if(ans == "{}") return "-1";
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    for(int i = 0; i < T; i++){
        cout << solve() << "\n";
    }
}
0