QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#835643#9925. LR Stringucup-team055#WA 35ms3588kbC++203.0kb2024-12-28 13:28:152024-12-28 13:28:16

Judging History

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

  • [2024-12-28 13:28:16]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:3588kb
  • [2024-12-28 13:28:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll ILL=2167167167167167167;
const int INF=2100000000;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,T b){if(b<a){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
bool yneos(bool a,bool upp=0){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;}
template<class T> void vec_out(vector<T> &p,int ty=0){
    if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
    else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}



void solve();
// CITRUS CURIO CITY / FREDERIC
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    rep(i, 0, t) solve();
}

void solve(){
    string S;
    cin >> S;
    int N = (int)S.size();
    vector<int> nextL(N + 1, INF), nextR(N + 1, INF), nextLR(N + 1, INF);
    for (int i = N - 1; i >= 0; i--){
        nextL[i] = nextL[i + 1];
        nextR[i] = nextR[i + 1];
        nextLR[i] = nextLR[i + 1];
        if (S[i] == 'L'){
            nextL[i] = i;
            if (i != N - 1 && S[i + 1] == 'R'){
                nextLR[i] = i;
            }
        }
        else{
            nextR[i] = i;
        }
    }
    int Q;
    cin >> Q;
    while (Q--){
        string T;
        cin >> T;
        if (T.front() == 'R' && S.front() == 'L'){
            cout << "No\n";
            continue;
        }
        if (T.back() == 'L' && S.back() == 'R'){
            cout << "NO\n";
            continue;
        }
        int ind = 0;
        rep(i, 0, T.size()){
            if (T[i] == 'L'){
                if (i != (int)T.size() && T[i + 1] == 'R'){
                    ind = nextLR[ind] + 1;
                }
                else{
                    ind = nextL[ind] + 1;
                }
            }
            else{
                ind = nextR[ind] + 1;
            }
            if (ind >= INF) break;
        }
        cout << (ind < INF ? "YES\n" : "NO\n");
    }
}

详细

Test #1:

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

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: 35ms
memory: 3588kb

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

result:

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