QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#840786 | #9925. LR String | Zawos# | WA | 58ms | 3612kb | C++20 | 2.7kb | 2025-01-03 02:53:49 | 2025-01-03 02:53:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
vii blocks(string &s) {
int n = s.size();
vii res;
int sz = 1;
rep(i, 1, n) {
if (s[i] != s[i - 1]) {
res.emplace_back(sz, s[i - 1] == 'L' ? 0 : 1);
sz = 0;
}
sz++;
}
res.emplace_back(sz, s[n - 1] == 'L' ? 0 : 1);
return res;
}
void solve() {
string s; cin >> s;
vii S = blocks(s);
int n = S.size();
vi O(n), Z(n);
rep(i, 0, n) {
O[i] = S[i].first * (S[i].second == 1);
Z[i] = S[i].first * (S[i].second == 0);
if (i)
O[i] += O[i - 1],
Z[i] += Z[i - 1];
}
int q; cin >> q;
while (q--) {
string t; cin >> t;
vii T = blocks(t);
bool ok = true;
int j = 0;
rep(i, 0, T.size()) {
if (j == n) {
ok = false;
break;
}
if (T[i].second == 0) { // Necesito L
if (S[j].second == 1) {
if (j + 1 == n) {
ok = false;
break;
}
j++;
}
int l = j, r = n - 1;
while (l <= r) {
int m = (l + r) / 2;
if (Z[m] - (i ? Z[i - 1] : 0) >= T[i].first)
r = m - 1;
else
l = m + 1;
}
if (l == n) {
ok = false;
break;
}
j = l + 1;
}else { // Necesito R
if (S[j].second == 0) {
if (j == 0) {
ok = false;
break;
}
j++;
}
int l = j, r = n - 1;
while (l <= r) {
int m = (l + r) / 2;
if (O[m] - (i ? O[i - 1] : 0) >= T[i].first)
r = m - 1;
else
l = m + 1;
}
if (l == n) {
ok = false;
break;
}
j = l + 1;
}
}
cout << (ok ? "YES" : "NO") << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int t; cin >> t;
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 58ms
memory: 3596kb
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 YES NO YES YES NO YES YES NO NO NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES NO NO YES YES YES NO NO NO NO NO NO NO NO YES NO NO NO YES YES NO NO NO YES NO NO NO YES NO YES YES YES YES YES YES YES YES NO YES NO YES NO NO YES YES YES...
result:
wrong answer 11th lines differ - expected: 'NO', found: 'YES'