QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#831310#9925. LR Stringucup-team4479#WA 80ms5668kbC++231.1kb2024-12-25 13:21:492024-12-25 13:21:49

Judging History

你现在查看的是最新测评结果

  • [2024-12-25 13:21:49]
  • 评测
  • 测评结果:WA
  • 用时:80ms
  • 内存:5668kb
  • [2024-12-25 13:21:49]
  • 提交

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;
}

详细

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'