Why TLE on TEST 5?
查看原帖
Why TLE on TEST 5?
244309
yuhaocheng楼主2021/8/14 10:12
#include <iostream>
using namespace std;

string s, sub;

bool check(int it, int pos) {
    if(it >= s.length()) {
        if(pos >= sub.length()) {
            return true;
        } else {
            return false;
        }
    }
    if(pos >= sub.length()) {
        return true;
    }
    if(s[it] != sub[pos]) {
        return check(it + 2, pos);
    } else {
        return check(it + 1, pos + 1) || check(it + 3, pos + 1);
    }
}

int main() {
    int t;
    cin >> t;
    while(t--) {
        cin >> s >> sub;
        cout << ((check(0, 0) || check(1, 0)) ? "YES" : "NO") << endl;
    }
}
2021/8/14 10:12
加载中...