QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#828911 | #9925. LR String | Yuey# | WA | 37ms | 3760kb | C++20 | 1.4kb | 2024-12-23 21:53:19 | 2024-12-23 21:53:21 |
Judging History
answer
# include <bits/stdc++.h>
# define imax(a , b) ((a) > (b) ? (a) : (b))
# define imin(a , b) ((a) < (b) ? (a) : (b))
# define rl ro << 1
# define rr ro << 1 | 1
using namespace std;
const int N = 1e6 + 511;
int ne[N][10];
void solve()
{
string s;
cin >> s;
int n = s.size();
s = " " + s;
for (int i = 1; i <= n; ++i) ne[i][0] = ne[i][1] = -1;
int l = -1 , r = -1;
for (int i = 0; i <= n; ++i){
while (l <= n && (l == -1 || l == i || s[l] != 'L')) ++l;
while (r <= n && (r == -1 || r == i || s[r] != 'R')) ++r;
if (l <= n) ne[i][0] = l;
if (r <= n) ne[i][1] = r;
}
int q;
cin >> q;
while (q--){
string t;
cin >> t;
int m = t.size();
t = " " + t;
if (t[1] == 'R' && s[1] == 'L') {
cout << "NO\n";
continue;
}
if (t[m] == 'L' && s[n] == 'R') {
cout << "NO\n";
continue;
}
int la = 0 , F = 0;
for (int i = 1; i <= m; ++i){
int fl = 0;
la = ne[la][(t[i] == 'R')];
if (la == -1) { F = 1; break; }
}
cout << (F ? "NO" : "YES") << "\n";
}
}
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin>>T;
while (T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3516kb
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: 37ms
memory: 3760kb
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 YES NO NO NO NO YES YES YES YES YES YES YES YES YES YES YES NO NO YES NO NO NO NO NO NO YES YES YES NO NO NO NO NO NO NO NO YES NO NO NO YES YES NO NO NO NO NO NO NO NO NO YES YES YES YES YES YES YES NO NO NO NO YES NO NO YES YES YES NO NO NO NO...
result:
wrong answer 438th lines differ - expected: 'NO', found: 'YES'