QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#828892 | #9925. LR String | Yuey# | TL | 0ms | 3804kb | C++20 | 1.4kb | 2024-12-23 21:35:33 | 2024-12-23 21:35:46 |
Judging History
answer
# include <bits/stdc++.h>
# define int long long
# 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[2];
void solve()
{
string s;
cin >> s;
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;
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();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
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...