QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#841454#9925. LR Stringwifi32767WA 40ms3668kbC++202.6kb2025-01-03 19:11:552025-01-03 19:12:05

Judging History

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

  • [2025-01-03 19:12:05]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:3668kb
  • [2025-01-03 19:11:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n'
#define yes cout << "YES" << endl
#define no cout << "No" << endl
const int MAX = 1e5 + 5, mod = 998244353;
const int N = 750;

void solve(){
    string s;
    cin >> s;
    int n = s.size();
    s = ' ' + s;
    vector<int> pre(n + 1, 0);
    for (int i = 1; i <= n; i ++){
        pre[i] = pre[i - 1] + (s[i] == 'L');
    }
    auto solve1 = [&](string t){
        int m = t.size();
        t = ' ' + t;
        if (s[1] == 'L' and t[1] == 'R') return false;
        if (s[n] == 'R' and t[m] == 'L') return false;
        int cur = 1;
        for (int i = 1; i <= n; i ++){
            if (s[i] == t[cur]) cur ++;
            if (cur > m) return true;
        }
        return false;
    };
    auto solve2 = [&](string t){
        int m = t.size();
        if (s[1] == 'L' and t[1] == 'R') return false;
        if (s[n] == 'R' and t[m] == 'L') return false;
        vector<array<int, 2>> a;
        int cnt = 1;
        for (int i = 1; i < m; i ++){
            if (t[i] == t[i - 1]) cnt ++;
            else{
                a.push_back({t[i - 1] == 'L', cnt});
                cnt = 1;
            }
        }
        a.push_back({t[m - 1] == 'L', cnt});
        int cur = 0;
        for (auto [x, y] : a){
            if (x == 0){
                int lk = cur, rk = n;
                while (lk < rk){
                    int mid = (lk + rk) >> 1;
                    if ((mid - pre[mid]) - (cur - pre[cur]) >= y) rk = mid;
                    else lk = mid + 1;
                }
                // cerr << lk << ' ';
                if ((lk - pre[lk]) - (cur - pre[cur]) < y) return false;
                cur = lk;
            }
            else{
                int lk = cur, rk = n;
                while (lk < rk){
                    int mid = (lk + rk) >> 1;
                    if (pre[mid] - pre[cur] >= y) rk = mid;
                    else lk = mid + 1;
                }
                // cerr << lk << ' ';
                if (pre[lk] - pre[cur] < y) return false;
                cur = lk;
            }
            
        }
        return true;
    };
    int q; cin >> q;
    for (int i = 0; i < q; i ++){
        string t; cin >> t;
        bool ans;
        if (t.size() > N) ans = solve1(t);
        else ans = solve2(t);
        if (ans) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int T=1;cin>>T;while(T--)
    solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3668kb

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: 40ms
memory: 3640kb

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

result:

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