Submission #6765

# Submission time Handle Problem Language Result Execution time Memory
6765 2014-07-05T18:44:39 Z cki86201 없는 등수 찾기 (GA7_rank) C++
0 / 100
4 ms 4212 KB
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;

#define X first
#define Y second
typedef long long ll;
typedef pair<int,int> Pi;

int c[400040], w[200020];
int f[200020];

int main()
{
	int r, n;
	int i;
	scanf("%d%d",&r,&n);
	for(i=1;i<=2*n;i++){
		char ch[2];
		scanf("%d%s",w+i,ch);
		c[i] = ch[0] == 'B';
	}
	n = 2*n;
	for(i=1;i<=n;i++)c[i+n] = c[i];
	int m = 2*n;
	f[0] = -1;
	for(i=1;i<=n;i++){
		int x;
		for(x = f[i-1]+1;x;x = f[x-1]+1){
			if(c[i] == c[x])break;
		}
		f[i] = x;
	}
	int j = 1;
	for(i=1;i<=m;i++,j++){
		while(j && c[i] == c[j])j = f[j-1] + 1;
		if(j == n)break;
	}
	if(i-n == n+1)printf("-1");
	else printf("%lld",(ll)r*(i-n));
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 4212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 4212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 4212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4212 KB Output isn't correct
2 Halted 0 ms 0 KB -