처음에 S를 T로 바꾸는 게임이라 해서 S->T를 생각해서 풀면서 메모리 초과를 2번 맞았다.
반대로 T->S로 만드는 방법을 생각해서 푸니 바로 맞았다.
생각없이 문제대로만 했다가는 풀지 못할 문제같다.
처음에 s가 t가 되는 과정을 구현하려다가 메모리초과 두번을 당했다..
#include<bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
string s, t; cin >> s >> t;
if (s == t) {
cout << 1 << '\n';
return 0;
}
while (s != t) {
if (t[t.length() - 1] == 'A') {
t.pop_back();
}
else if (t[t.length() - 1] == 'B') {
t.pop_back();
reverse(t.begin(), t.end());
}
if (s == t) {
cout << 1 << '\n';
return 0;
}
if (t.length() <= s.length()) {
break;
}
}
cout << 0 << '\n';
return 0;
}