QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#834249#9925. LR Stringyyf_0404#WA 29ms5664kbC++171.4kb2024-12-27 14:19:382024-12-27 14:19:38

Judging History

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

  • [2024-12-27 14:19:38]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:5664kb
  • [2024-12-27 14:19:38]
  • 提交

answer

// k.cpp
#include <bits/stdc++.h>
using namespace std;
char s[500005], t[500005];
int n, nxt[500005][3];
void solve() {
    cin >> s;
    n = strlen(s);
    int la[3] = {n, n, n};
    for (int i = n - 1; i >= 0; i--) {
    	if (s[i] == 'L') {
    		la[0] = i;
    		if (s[i + 1] == 'R') {
    			la[2] = i;
    		}
    	}
    	else {
    		la[1] = i;
    	}
    	memcpy(nxt[i], la, sizeof(la));
    }
    int q;
    cin >> q;
    while (q--) {
    	cin >> t;
    	int m = strlen(t), len = n, cur = 0, st = 0;
    	if (t[0] == 'R') {
    		if (s[0] == 'R') {
    			cur += 1;
    			st += 1;
    		}
    		else {
    			printf("NO\n");
    			continue;
    		}
    	}
    	if (t[m - 1] == 'L') {
    		if (s[len - 1] == 'L') {
    			m -= 1;
    			len -= 1;
    		}
    		else {
    			printf("NO\n");
    			continue;
    		}
    	}
    	for ( ; st < m; st++) {
    		if (cur > len) {
    			cur = len + 1;
    			break;
    		}
    		if (t[st] == 'L') {
    			if (st + 1 < m && t[st + 1] == 'R') {
    				cur = nxt[cur][2] + 2;
    				st += 1;
    			}
    			else {
    				cur = nxt[cur][0] + 1;
    			}
    		}
    		else {
    			cur = nxt[cur][1] + 1;
    		}
    	}
    	// cout << cur << endl;
    	printf(cur > len ? "NO\n" : "YES\n");
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.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: 29ms
memory: 3716kb

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
YES
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
N...

result:

wrong answer 55th lines differ - expected: 'NO', found: 'YES'