You are viewing a single comment's thread. Return to all comments →
#include "bits/stdc++.h" using namespace std; constexpr bool is_upper(char c) { return c < 'a'; } constexpr char upper(char c) { return is_upper(c) ? c : c-32; } bool soln(std::string_view a, std::string_view b) { using B = std::bitset<1001>; using A = std::array<B, 1001>; A cache; cache[0][0] = true; auto const asize = a.size(), bsize = b.size(); for (auto x = 0; x < asize; ++x) { if (cache[x].none()) { break; } for (auto y = 0; y < bsize+1; ++y) { if (!cache[x][y]) { continue; } cache[x+1][y+1] = cache[x+1][y+1] || (y < bsize && upper(a[x]) == b[y]); cache[x+1][y] = bool{cache[x+1][y]} || !is_upper(a[x]); } } return cache[asize][bsize]; } int main() { int T; scanf("%d", &T); for(int ii = 0; ii < T; ++ ii) { string a, b; cin >> a >> b; puts(soln(a, b) ? "YES" : "NO"); } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Abbreviation
You are viewing a single comment's thread. Return to all comments →