#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long r;
int n;
char s[400010]={0},p[800020]={0};
long long x[400010]={0};
long long ans=-1;
long long dist(long long p,long long q){
if(p<q) return q-p;
else return r - (p-q);
}
int main()
{
int i;
int first,last;
//long long sum = 0;
char *temp;
char t[2]={0};
scanf("%lld%d",&r,&n);
n *= 2;
for(i=0;i<n;i++){
scanf("%lld%s",&x[i],t);
s[i] = t[0];
}
for(i=0;i<n;i++){
if(s[i] == 'W') p[i] = 'B';
else p[i] = 'W';
}
for(i=0;i<n;i++) p[i+n] = p[i];
temp = strstr(p,s);
if(temp == NULL){
printf("-1\n");
return 0;
}
first = (int)(temp - p);
reverse(s,s+n);
reverse(p,p+2*n);
temp = strstr(p,s);
last = (int)(temp-p);
//for(i=0;i<n;i++) sum += dist(x[i],x[(i+first)%n]);
ans = r*first;
if(ans > r*last) ans = r*last;
printf("%lld\n",ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
5384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
5384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
5384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
5384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |