QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#831310 | #9925. LR String | ucup-team4479# | WA | 80ms | 5668kb | C++23 | 1.1kb | 2024-12-25 13:21:49 | 2024-12-25 13:21:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int nxtL[N], nxtR[N];
void solve() {
string s, t;
cin >> s;
int n = s.length(), q;
int lstL = n, lstR = n;
nxtL[n] = nxtR[n] = n;
for (int i = n - 1; i >= 0; --i) {
nxtL[i] = lstL, nxtR[i] = lstR;
if (s[i] == 'L') lstL = i;
else lstR = i;
}
cin >> q;
while (q--) {
cin >> t;
int m = t.length();
if (t[0] == 'R' && s[0] != 'R' || t[m - 1] == 'L' && s[m - 1] != 'L') {
cout << "NO" << endl;
continue;
}
int now = 0;
if (t[0] == s[0]) now = 0;
else now = t[0] == 'L' ? nxtL[0] : nxtR[0];
for (int i = 1; i < m; ++i) {
// cout << now << " " << i << endl;
if (t[i] == 'L') now = nxtL[now];
else now = nxtR[now];
}
if (now >= n) cout << "NO" << endl;
else cout << "YES" << endl;
}
}
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cout.tie(0);
int T;
cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5664kb
input:
2 RRLLRRLL 4 LLLLL LLR LRLR R RLLLLLL 3 LLLLL RL RRL
output:
NO YES NO YES YES YES NO
result:
ok 7 lines
Test #2:
score: -100
Wrong Answer
time: 80ms
memory: 5668kb
input:
100000 RRLLR 4 R R R R LRLLL 6 R L L L L R RLLRR 1 L LRLLL 3 R L L RLRRL 2 LRRRR RRRL LRLRR 2 L R RRLRL 4 RLRLR RLLL LR RLL RLRLL 8 R R R L L L R L RLLRR 7 R LL RL R L L L LLRLR 2 L R RRRRL 1 RLLLR RRLLL 2 L L RLLRL 1 RLLRL LRLLL 5 RLRLL RLLLR RRRRL LLRRR RLLRR LRLLL 3 RRLL R RL LLRRL 3 L R LLLRR RR...
output:
YES YES YES YES NO YES YES YES YES NO NO NO YES YES NO NO YES NO NO NO YES YES YES YES YES NO NO NO YES NO YES YES YES YES NO NO NO YES NO NO NO NO YES NO NO NO NO NO NO NO NO YES NO NO NO NO YES NO NO NO YES NO NO NO YES NO NO YES YES NO YES YES YES YES NO YES NO NO NO NO NO YES YES NO NO NO YES YE...
result:
wrong answer 16th lines differ - expected: 'YES', found: 'NO'