QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#555468 | #8046. Rock-Paper-Scissors Pyramid | code_side-effect | RE | 0ms | 3804kb | C++20 | 884b | 2024-09-09 23:36:36 | 2024-09-09 23:36:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 1e5 + 6;
int a[N];
int cmp(char a , char b){
if(a == b) return 0 ;
if(a == 'S' && b == 'P') return 1;
else if(a == 'P' && b == 'R') return 1;
else if(a == 'R' && b == 'S') return 1;
else return -1 ;
}
void solve(){
string s;
cin >> s;
i64 n = s.size();
s = ' ' + s ;
for(int i = 1 ; i <= n ; i++){
if(cmp(s[i] , s[i-1]) == 1) a[i] = a[i-1] - 1;
else if(cmp(s[i] , s[i-1]) == -1) a[i] = a[i-1] + 1 ;
else a[i] = a[i-1];
}
int min = 1e9,id = -1;
for(int i = 1 ;i<=n;i++){
if(min > a[i]){
min = a[i];
id = i;
}
}
cout << s[id] << "\n";
}
int main(){
int t = 1;
cin >> t;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
input:
2 SPR SPSRRP
output:
S P
result:
ok 2 lines
Test #2:
score: -100
Runtime Error
input:
1 RPPSRPPRSRSRRRPPSPRPRSRRSRRPPPRSPSSRRRSPPPRRRPRRRSSRPSSRPRRPSRRRPRSRPSRPSRRSPPRPRRRSPRSSSRPRRRPPSRRRRPPSRSRRRPRPRPRPPRRSRRPSRPPSRRRSRRSRRSPSRPRPSPSSRRSPSPSRPRRRPPRSRSPSPPRRPRSRPPSSSRPSPRRPSSSPRRSRRSRRSRSPSSSSRSSPPRRRRPRRRSPSRSPRSSPRSPSPRPRRRPPRPPRPPPSRRRRSSPRRSRRRPRRRSSRRPSRPPRSPPSPPPSPSPSPPSSPRRR...