QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#624042#8046. Rock-Paper-Scissors PyramidREN5511WA 12ms5268kbC++141.8kb2024-10-09 14:47:202024-10-09 14:47:21

Judging History

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

  • [2024-10-09 14:47:21]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:5268kb
  • [2024-10-09 14:47:20]
  • 提交

answer

#include <iostream>
#include <vector>
using namespace std;
string tar;
char win(char p1,char p2) {
    if (p1 == 'S') {
        if (p2 == 'S') {
            return 'S';
        }
        else if (p2 == 'P') {
            return 'S';
        }
        else {
            return 'R';
        }
    }
    else if (p1 == 'P') {
        if (p2 == 'S') {
            return 'S';
        }
        else if (p2 == 'P') {
            return 'P';
        }
        else {
            return 'P';
        }
    }
    else {
        if (p2== 'S') {
            return 'R';
        }
        else if (p2 == 'P') {
            return 'P';
        }
        else {
            return 'R';
        }
    }
    return '$';
}
char solve(int l,int r) {
    if (r - l+1 <= 2) {
        return win(tar[r], tar[l]);
    }
    int midl = (l + r) / 2, midr = (l + r) / 2 + 1;
    if ((r - l + 1) % 2) {
        int mid = midl;
        midl--;
        char a= solve(l, midl), b= solve(midr, r);
        if (win(a, tar[mid]) != tar[mid]) {
            return a;
        }
        else if (win(b, tar[mid]) != tar[mid]) {
            return b;
        }
        else {
            return win(win(a, tar[mid]), win(b, tar[mid]));
        }
    }
    else {
        char who = win(tar[midl], tar[midr]);
        if (who == tar[midl] && who == tar[midr]) {
            return win(solve(l, midl), solve(midr, r));
        }
        else if (who == tar[midl]) {
            return solve(l, midl);
        }
        else {
            return solve(midr, r);
        }
    }
}
int main()
{
    int t;
    cin >> t;
    while (t--) {
        cin >> tar;
        tar = '$' + tar;
        cout<<solve(1, tar.size()-1)<<"\n";
    }
    return 0;
}

详细

Test #1:

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

input:

2
SPR
SPSRRP

output:

S
P

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 12ms
memory: 5224kb

input:

1
RPPSRPPRSRSRRRPPSPRPRSRRSRRPPPRSPSSRRRSPPPRRRPRRRSSRPSSRPRRPSRRRPRSRPSRPSRRSPPRPRRRSPRSSSRPRRRPPSRRRRPPSRSRRRPRPRPRPPRRSRRPSRPPSRRRSRRSRRSPSRPRPSPSSRRSPSPSRPRRRPPRSRSPSPPRRPRSRPPSSSRPSPRRPSSSPRRSRRSRRSRSPSSSSRSSPPRRRRPRRRSPSRSPRSSPRSPSPRPRRRPPRPPRPPPSRRRRSSPRRSRRRPRRRSSRRPSRPPRSPPSPPPSPSPSPPSSPRRR...

output:

R

result:

ok single line: 'R'

Test #3:

score: -100
Wrong Answer
time: 8ms
memory: 5268kb

input:

1
PPPPPSPPPRPPPPRRPSRPPRSSRPPPPPPRPPPPRPPSPPPPPPPRPPRRPPRPPSPPPPRRPSPRSPPPPPPRRRPRPRPPPPPPRPPPPPPPSPPPPPPPPRPPPPSPPRPPPPPSPPRPPPSRPPPPRPPRPPRPPPSPPPPPPPRPPRRPPSPRPRPPPPPRPPPPPPPRPRRRSPPPPPSPSPSRPRPSPSPPPPPRSPPPPPRPPPRPPPPPPSRRRPPPPRPSPPSRPPRPPRPPPRRSPPPRRRPPRPPPPPRPPPSPRPPRPPPRPSPPPRPPPPPRRPPSPRPRPR...

output:

R

result:

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