QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#537356#8046. Rock-Paper-Scissors Pyramidrotcar07WA 20ms9532kbC++141.1kb2024-08-30 10:49:002024-08-30 10:49:00

Judging History

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

  • [2024-08-30 10:49:00]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:9532kb
  • [2024-08-30 10:49:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int main(){
    int t;cin>>t;
    while(t--){
        vector<int> v;
        string s;cin>>s;
        auto trans=[&](char c){if(c=='R')return 0;if(c=='P')return 1;return 2;};
        v.push_back(trans(s[0]));
        for(int i=1;i<s.size();i++)if(s[i]!=s[i-1]) v.push_back(trans(s[i]));
        if(v.size()==1)cout<<"RPS"[v[0]]<<'\n';
        else{
            int a=v[0],b=v[1];
            stack<int> st;
            int sb=-1;
            auto win=[&](int x,int y){return x==(y+1)%3;};
            for(int i=2;i<v.size();i++){
                if(i==b)continue;
            while(!st.empty()&&win(a,st.top())) st.pop();
            if(st.empty()) sb=-1;
                if(win(b,a)) a=b,b=v[i];
                else{
                    if(win(v[i],b)) swap(a,b);
                    else st.push(a),sb=(~sb?sb:a),a=b,b=v[i];
                }
            }
            while(!st.empty()&&win(a,st.top())) st.pop();
            if(st.empty()) sb=-1;
            if(~sb) cout<<"RPS"[sb]<<'\n';
            else cout<<"RPS"[win(a,b)?a:b]<<'\n';
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
SPR
SPSRRP

output:

S
P

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 20ms
memory: 9532kb

input:

1
RPPSRPPRSRSRRRPPSPRPRSRRSRRPPPRSPSSRRRSPPPRRRPRRRSSRPSSRPRRPSRRRPRSRPSRPSRRSPPRPRRRSPRSSSRPRRRPPSRRRRPPSRSRRRPRPRPRPPRRSRRPSRPPSRRRSRRSRRSPSRPRPSPSSRRSPSPSRPRRRPPRSRSPSPPRRPRSRPPSSSRPSPRRPSSSPRRSRRSRRSRSPSSSSRSSPPRRRRPRRRSPSRSPRSSPRSPSPRPRRRPPRPPRPPPSRRRRSSPRRSRRRPRRRSSRRPSRPPRSPPSPPPSPSPSPPSSPRRR...

output:

P

result:

wrong answer 1st lines differ - expected: 'R', found: 'P'