QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749473 | #8046. Rock-Paper-Scissors Pyramid | moon | WA | 7ms | 5664kb | C++14 | 4.3kb | 2024-11-15 01:18:06 | 2024-11-15 01:18:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
string s;
cin >> s;
string t = "";
int n = s.size();
for(int i = 0; i < n - 1; ++i) {
if(s[i] != s[i + 1]) {
t.push_back(s[i]);
}
}
t.push_back(s.back());
n = t.size();
auto cal = [&](string s) -> char {
while(n > 1) {
for(int i = 0; i < n - 1; ++i) {
if(s[i] != s[i + 1]) {
if(s[i] == 'S') {
if(s[i + 1] == 'R') {
s[i] = 'R';
}
} else if(s[i] == 'P') {
if(s[i + 1] == 'S') {
s[i] = 'S';
}
} else {
if(s[i + 1] == 'P') {
s[i] = 'P';
}
}
}
}
n--;
}
return s[0];
};
// cout << cal(t) << '\n';
auto check = [&](string t) -> bool {
map<char, bool> mp;
for(auto i : t) {
mp[i] = true;
}
if(mp.size() == 1) {
cout << mp.begin() -> first << '\n';
return true;
} else if(mp.size() == 2) {
vector<int> type(3);
for(auto [x, y] : mp) {
if(x == 'P') {
type[0] = 1;
} else if(x == 'S') {
type[1] = 1;
} else {
type[2] = 1;
}
}
if(type[0] + type[1] == 2) {
cout << "S\n";
} else if(type[1] + type[2] == 2) {
cout << "R\n";
} else {
cout << "P\n";
}
return true;
}
return false;
};
if(check(t)) {
return ;
}
vector<string> a = {"RSP", "SPR", "PRS"};
// vector<string> b = {"PSR", "RPS", "SRP"};
vector<int> inxa(3, 1e6 + 1);
vector<int> inxb(3, 1e6 + 1);
for(int i = 0; i < 3; ++i) {
if(t.find(a[i]) != string::npos) {
inxa[i] = t.find(a[i]);
}
}
reverse(t.begin(), t.end());
for(int i = 0; i < 3; ++i) {
if(t.find(a[i]) != string::npos) {
inxb[i] = t.find(a[i]);
}
}
reverse(t.begin(), t.end());
int aa = -1, bb = -1;
int minna = 1e6 + 1, minnb = 1e6 + 1;
for(int i = 0; i < 3; ++i) {
// cout << inxa[i] << ' ' << inxb[i] << '\n';
if(inxa[i] < minna) {
minna = inxa[i];
aa = i;
}
if(inxb[i] < minnb) {
minnb = inxb[i];
bb = i;
}
}
assert(!(aa == -1 and bb == -1));
if(aa == -1 || bb == -1) {
int tem = 0;
if(aa != -1) {
t = t.substr(0, minna) + a[aa][0];
} else {
t = a[bb][0] + t.substr(n - minnb, minnb);
}
// check(t);
assert(check(t));
return ;
}
if(aa == bb) {
cout << a[aa][0] << '\n';
return ;
} else {
auto call = [&](int x, int y) -> char {
char xx = a[x][0];
char yy = a[y][0];
if(xx == yy) {
return xx;
}
if(xx == 'P') {
if(yy == 'S') {
return 'S';
} else {
return 'P';
}
} else if(xx == 'S') {
if(yy == 'P') {
return 'S';
} else {
return 'R';
}
} else {
if(yy == 'S') {
return 'R';
} else {
return 'P';
}
}
};
minnb = n - minnb - 1;
char tem = call(minna, minnb);
t = t.substr(0, minna) + tem + t.substr(minnb + 1, n - minnb - 1);
// check(t);
assert(check(t) == true);
// a3bb
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
cin >> t;
while(t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3632kb
input:
2 SPR SPSRRP
output:
S P
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 5664kb
input:
1 RPPSRPPRSRSRRRPPSPRPRSRRSRRPPPRSPSSRRRSPPPRRRPRRRSSRPSSRPRRPSRRRPRSRPSRPSRRSPPRPRRRSPRSSSRPRRRPPSRRRRPPSRSRRRPRPRPRPPRRSRRPSRPPSRRRSRRSRRSPSRPRPSPSSRRSPSPSRPRRRPPRSRSPSPPRRPRSRPPSSSRPSPRRPSSSPRRSRRSRRSRSPSSSSRSSPPRRRRPRRRSPSRSPRSSPRSPSPRPRRRPPRPPRPPPSRRRRSSPRRSRRRPRRRSSRRPSRPPRSPPSPPPSPSPSPPSSPRRR...
output:
P
result:
wrong answer 1st lines differ - expected: 'R', found: 'P'