QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361209 | #8287. Caught in the Middle | paoxiaomo# | WA | 0ms | 3844kb | C++20 | 1.5kb | 2024-03-22 22:15:10 | 2024-03-22 22:15:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
void solve()
{
int n;
string s;
cin >> n >> s;
int t = count(s.begin(), s.end(), 'L');
if (t == 0 || t == n)
{
cout << "Alice" << endl;
return;
}
s = " " + s;
vector<int> l(n + 2), r(n + 2), vi(n + 2), is(n + 2);
queue<int> q;
for (int i = 1; i <= n; i++)
{
l[i] = i - 1;
r[i] = i + 1;
}
vi[0] = 1;
vi[n + 1] = 1;
for (int i = 1; i < n; i++)
{
if (s[i] == 'R' && s[i + 1] == 'L')
{
vi[i] = 1;
vi[i + 1] = 1;
is[i] = is[i + 1] = 1;
l[r[i + 1]] = l[i];
r[l[i]] = r[i + 1];
if (!vi[l[i]])
q.push(l[i]), vi[l[i]] = 1;
}
}
while (!q.empty())
{
int p1 = q.front();
q.pop();
int p2 = r[p1];
if (s[p1] == 'R' && s[p2] == 'L')
{
is[p1] = is[p2] = 1;
l[r[p2]] = l[p1];
r[l[p1]] = r[p2];
if (!vi[l[p1]])
q.push(l[p1]), vi[l[p1]] = 1;
}
}
int num = accumulate(is.begin(), is.end(), 0);
if (num == n)
{
cout << "Bob" << endl;
}
else
{
cout << "Alice" << endl;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
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: 3552kb
input:
20 10 RLRRRRLLRR 10 LRLLLLRRLR 6 RLRLRL 10 LLRLRRRRLR 6 LRRLLL 3 RLR 5 LLRRR 6 RRRRRL 9 LRRRLRRLR 1 R 10 RRRLLRRLLL 6 LRLLLR 9 LLRLRLRLR 7 RRRRLRR 2 LL 10 RRRLLRRLRR 2 RL 7 RRLRRLR 3 LLR 10 LLRLRRRLLR
output:
Alice Alice Bob Alice Alice Alice Alice Alice Alice Alice Bob Alice Alice Alice Alice Alice Bob Alice Alice Alice
result:
ok 20 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
20 7 LRLLRRR 8 LRLRLRRR 3 RLL 10 RLRLRLRLRL 10 RLRLRLRLRL 6 RLLLRL 10 RLRLRLRLLL 5 RLRRR 2 LL 10 RRRRLRLRLL 7 LLRRLLR 3 LRR 10 RRRRRLLLLL 10 RLRRRLRLRR 2 LR 6 RRLLLL 4 RRLR 10 LRLRLLRLRR 4 LRLL 10 RRLLRRRLLL
output:
Alice Alice Alice Bob Bob Alice Alice Alice Alice Alice Alice Alice Bob Alice Alice Alice Alice Alice Alice Bob
result:
ok 20 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
20 8 LLLRRRRR 10 LRRRLRLLRL 10 RLRLRLRLRL 6 RRLRRL 10 RLLLLRLLRR 2 RR 8 LLRRRLRL 10 LRLRLRRRRR 4 RRLL 5 LLRLL 10 RLRRLLRLRL 1 R 10 RLLRRLRLLL 10 LLLRLLRLRR 10 LRRLRLLRRR 3 RRL 10 RRRLRLLRLL 1 L 3 RRL 5 LRRLL
output:
Alice Alice Bob Alice Alice Alice Alice Alice Bob Alice Bob Alice Alice Alice Alice Alice Bob Alice Alice Alice
result:
ok 20 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
20 6 RLRLLL 2 RL 10 LRRRLRLRLR 7 LLLRRRR 3 RRR 3 LRL 10 LRLRRLLLLR 10 RRLLLLRLLR 5 LLLLL 10 RLRLLRLRLR 8 RRLRLRLL 9 RRLRLRRLR 8 RLRLRLRL 1 R 10 RRLRLRRRLL 3 LLL 1 L 6 LLLRLL 10 RLRLRLRRLL 3 LRL
output:
Alice Bob Alice Alice Alice Alice Alice Alice Alice Alice Bob Alice Bob Alice Alice Alice Alice Alice Bob Alice
result:
ok 20 lines
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3836kb
input:
20 4 RLRL 10 RRRLLRLLRL 10 RLRRLRLRLL 4 RLRL 4 RLRL 2 LR 2 RL 1 R 6 RRLRLL 10 RRRLRRLLLL 1 L 10 RLLRRRLLLL 2 RL 8 RRRRLLLL 10 RRLRRRLLLL 10 RLRRLRLRLL 10 RRLLRRLRLL 1 L 4 RLRL 4 RLRL
output:
Bob Bob Bob Bob Bob Alice Bob Alice Bob Alice Alice Alice Bob Bob Alice Bob Bob Alice Bob Bob
result:
wrong answer 10th lines differ - expected: 'Bob', found: 'Alice'