結果

問題 No.2231 Surprising Flash!
ユーザー umncumnc
提出日時 2023-02-26 17:02:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,625 bytes
コンパイル時間 543 ms
コンパイル使用メモリ 69,400 KB
実行使用メモリ 10,272 KB
最終ジャッジ日時 2023-10-12 08:02:06
合計ジャッジ時間 7,156 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

string solve(int n, int m, string s1, string s2) {
    int k = s2.size();

    // s2を構成する文字がs1に含まれるかを調べる
    bool exist[26] = {};
    for (char c : s2) {
        if (c != '?') {
            exist[c - 'a'] = true;
        }
    }
    for (char c : s1) {
        if (c != '?' && !exist[c - 'a']) {
            return "-1"; // s1に含まれない文字がs2に含まれる場合
        }
    }

    // s2を含む部分列を構成する
    string ans(n, ' ');
    for (int i = 0; i <= n - k; i++) {
        bool ok = true;
        for (int j = 0; j < k; j++) {
            if (s2[j] != '?' && s1[i+j] != s2[j]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            string tmp = s1;
            for (int j = 0; j < k; j++) {
                if (s2[j] != '?') {
                    tmp[i+j] = s2[j];
                }
            }
            for (int j = 0; j < n; j++) {
                if (tmp[j] == '?') {
                    tmp[j] = 'a'; // ? を a に置き換える
                }
            }
            if (ans == " " || tmp < ans) {
                ans = tmp;
            }
        }
    }

    if (ans == " ") {
        return "-1"; // s2を含む部分列が存在しない場合
    } else {
        return ans;
    }
}

int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        int n, m;
        string s1, s2;
        cin >> n >> m >> s1 >> s2;
        cout << solve(n, m, s1, s2) << endl;
    }
    return 0;
}
0