QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#619265#8046. Rock-Paper-Scissors Pyramidmhw#WA 74ms54348kbC++201.6kb2024-10-07 13:41:542024-10-07 13:41:56

Judging History

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

  • [2024-10-07 13:41:56]
  • 评测
  • 测评结果:WA
  • 用时:74ms
  • 内存:54348kb
  • [2024-10-07 13:41:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 P = 998244353;
const int N = 1e6 + 6;
vector<int> g[N];
int in[N];
void solve() {
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i <= n; i++)
    {
        g[i].clear();
        in[i] = 0;
    }
    s = " " + s;
    int lst = 1;
    for (int i = 1; i <= n; i++)
    {
        if (s[i] == s[lst]) ;
        else 
        {
            if (s[i] == 'S') // 剪刀
            {
                if (s[lst] == 'P') g[lst].push_back(i);
                else if (s[lst] == 'R') g[i].push_back(lst);
            }
            else if (s[i] == 'P') // 布
            {
                if (s[lst] == 'S') g[i].push_back(lst);
                else if (s[lst] == 'R') g[lst].push_back(i);
            }
            else if (s[i] == 'R') // 石头
            {
                if (s[lst] == 'P') g[i].push_back(lst);
                else if (s[lst] == 'S') g[lst].push_back(i);
            }
            lst = i;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (auto j: g[i]) in[j]++;
    }
    queue<int> q;
    vector<int> v;
    for (int i = 1; i <= n; i++) 
        if (in[i] == 0) q.push(i);
    while (q.size())
    {
        auto u  = q.front();
        v.push_back(u);
        q.pop();
        for (auto v: g[u])
        {
            in[v]--;
            if (in[v] == 0) q.push(v);
        }
    }
    cout << s[v.back()] << '\n';
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;    
    while (t--) solve();
    return 0;
}

/*
2
SPSRRPR
SPRS
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
SPR
SPSRRP

output:

S
P

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 74ms
memory: 54348kb

input:

1
RPPSRPPRSRSRRRPPSPRPRSRRSRRPPPRSPSSRRRSPPPRRRPRRRSSRPSSRPRRPSRRRPRSRPSRPSRRSPPRPRRRSPRSSSRPRRRPPSRRRRPPSRSRRRPRPRPRPPRRSRRPSRPPSRRRSRRSRRSPSRPRPSPSSRRSPSPSRPRRRPPRSRSPSPPRRPRSRPPSSSRPSPRRPSSSPRRSRRSRRSRSPSSSSRSSPPRRRRPRRRSPSRSPRSSPRSPSPRPRRRPPRPPRPPPSRRRRSSPRRSRRRPRRRSSRRPSRPPRSPPSPPPSPSPSPPSSPRRR...

output:

P

result:

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