結果

問題 No.2226 Hello, Forgotten World!
ユーザー AngrySadEightAngrySadEight
提出日時 2022-12-01 01:57:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 71,464 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 02:39:07
合計ジャッジ時間 1,951 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

void solve(){
    int N;
    cin >> N;
    string S;
    cin >> S;

    bool pos = false;
    string ans;
    for (int i = 0; i < N; i++) ans += 'z';

    string hw = "helloworld";
    for (int i = 0; i < N - 9; i++){
        string Sb = S.substr(i, 10);
        bool can = true;
        for (int j = 0; j < 10; j++){
            if (Sb[j] != hw[j] && Sb[j] != '?'){
                can = false;
            }
        }
        if (!can) continue;
        pos = true;
        string T;
        for (int j = 0; j < N; j++){
            if (S[j] == '?'){
                if (j >= i && j < i + 10){
                    T += hw[j - i];
                }
                else{
                    T += 'a';
                }
            }
            else{
                T += S[j];
            }
        }
        if (T < ans){
            ans = T;
        }
    }
    if (pos) cout << ans << endl;
    else cout << -1 << endl;
    return;
}

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