QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#828900 | #9925. LR String | Yuey# | TL | 0ms | 3600kb | C++20 | 1.6kb | 2024-12-23 21:44:13 | 2024-12-23 21:44:14 |
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 = 2e5 + 511;
vector<int> e[10];
void solve()
{
string s;
cin >> s;
// for (int i = 1; i <= (1e6 )/ 2; ++i) s += 'R';
// for (int i = 1; i <= (1e6 )/ 2; ++i) s += 'L';
int n = s.size();
s = " " + s;
for (int i = 0; i < 2; ++i) e[i].clear();
for (int i = 1; i <= n; ++i){
if (s[i] == 'L') e[0].push_back(i);
else e[1].push_back(i);
}
int q;
cin >> q;
while (q--){
string t;
cin >> t;
// for (int i = 1; i <= (1e6 )/ 2; ++i) t += 'R';
// for (int i = 1; i <= (1e6 )/ 2; ++i) t += 'L';
// t += 'R';
int m = t.size();
t = " " + t;
if (t[1] == 'R' && s[1] == 'L') {
cout << "NO\n";
return;
}
if (t[m] == 'L' && s[n] == 'R') {
cout << "NO\n";
return;
}
int la = 0 , F = 0;
for (int i = 1; i <= m; ++i){
int fl = 0;
if (la == n) {F = 1; break; }
int pos = (t[i] == 'R');
auto x = lower_bound(e[pos].begin() , e[pos].end() , la + 1);
if (x == e[pos].end()) {F = 1; break; }
la = *x;
}
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: 3600kb
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
Time Limit Exceeded
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 YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES Y...