QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#368335 | #8512. Harmonic Operations | ucup-team134# | WA | 1ms | 4060kb | C++17 | 1.0kb | 2024-03-27 01:01:15 | 2024-03-27 01:01:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200050;
char s[N];
int f[N];
int main(){
scanf("%s",s+1);
int n=strlen(s+1);
bool pal=true;
for(int i=1;i<=n;i++)if(s[i]!=s[n-i+1])pal=false;
f[0]=0;f[1]=0;
for(int i=2;i<=n;i++){
int tmp=f[i-1];
while(tmp && s[i]!=s[tmp+1])tmp=f[tmp];
if(s[i]==s[tmp+1])tmp++;
f[i]=tmp;
}
int now=0,cyc=n;
for(int i=2;i<=2*n;i++){
while(now && s[(i-1)%n+1]!=s[now+1])now=f[now];
if(s[(i-1)%n+1]==s[now+1])now++;
if(now==n){
cyc=i-n;
break;
}
}
//printf("pal: %i, cyc: %i\n",pal,cyc);
int k;
scanf("%i",&k);
int rev=0,rot=0;
map<pair<int,int>,int> cnt;
cnt[{rev,rot}]++;
ll ans=0;
for(int i=1;i<=k;i++){
char t;
scanf("\n%c",&t);
if(t=='I'){
if(!pal)rev^=1;
}else{
int d;
scanf("%i",&d);
d%=cyc;
if(t=='L')d=(cyc-d)%cyc;
if(rev)d=(cyc-d)%cyc;
rot=(rot+d)%cyc;
}
//printf("%i %i\n",rev,rot);
ans+=cnt[{rev,rot}];
cnt[{rev,rot}]++;
}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3788kb
input:
pda 2 R 2 L 2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3776kb
input:
aaa 4 R 1 I I R 1
output:
10
result:
ok 1 number(s): "10"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
caso 6 L 1 I I R 1 I I
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq 100 L 12 I R 47 L 54 I I R 80 L 86 L 19 R 5 L 53 L 40 R 20 L 11 R 40 I I R 66 R 6 L 76 L 93 R 39 I I L 24 R 59 R 99 L 52 I I R 77 L 11 R 60 L 16 I L 40 I R 35 L 64 R 11 L 34 I R 35 I L 87 I I L 42 L ...
output:
5050
result:
ok 1 number(s): "5050"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 4060kb
input:
wewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewewe 100 R 83 R 34 I I R 87 R 74 L 98 I L 77 L 8 R 23 L 94 I I L 79 L 87 L 47 L 85 L 49 L 7 I I R 97 R 15 I R 66 L 8 R 62 R 68 I I R 32 R 24 R 36 L 60 R 75 R 77 I L 42 I L 61 I I R 78 R 51 L 98 I L 77 I I...
output:
1295
result:
wrong answer 1st numbers differ - expected: '2556', found: '1295'