結果

問題 No.2226 Hello, Forgotten World!
ユーザー piratapirata
提出日時 2023-02-25 00:15:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,223 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 66,668 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-11 07:11:34
合計ジャッジ時間 1,314 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 26 ms
4,372 KB
testcase_02 AC 5 ms
4,368 KB
testcase_03 AC 5 ms
4,372 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 6 ms
4,368 KB
testcase_06 AC 3 ms
4,368 KB
testcase_07 AC 4 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 4 ms
4,368 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] == '?'){
                // 基準点から10以内であれば、helloworldにする
                if (j >= i && j < i + 10){
                    // cout << j << " " << i << endl;
                    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