답안 #6008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
6008 2014-06-14T10:33:38 Z model_code 돌 옮기기 (GA7_stone) C++
100 / 100
108 ms 15748 KB
#include<stdio.h>
#define min2(a,b) ((a)<(b)?(a):(b))

typedef long long lld;

int n, fail[1001001];
char col[1001001], riv[2002002];
lld ba[1001001], r, gap, dap=-1;

int main(){
	int i, j=1;
	scanf("%lld%d", &r, &n), n*=2;
	for(i=1; i<=n; i++){
		scanf("%lld %c", &ba[i], &col[i]);
		riv[i]=riv[n+i]=col[i];
	}
	col[n+1]='$';
	for(i=2; i<=n; i++){
		while(col[i]!=col[j]){
			if(j==1){
				j=0;
				break;
			}
			j=fail[j-1]+1;
		}
		fail[i]=j++;
	}
	for(i=j=1; i<=2*n; i++){
		while(riv[i]==col[j] || j==n+1){
			if(j==1){
				j=0;
				break;
			}
			j=fail[j-1]+1;
		}
		if(j==n){
			gap=r*min2(i-n, 2*n-i);
			if(dap==-1)dap=gap;
			else dap=min2(dap,gap);
		}
		j++;
	}
	printf("%lld", dap);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 15748 KB Output is correct
2 Correct 0 ms 15748 KB Output is correct
3 Correct 0 ms 15748 KB Output is correct
4 Correct 0 ms 15748 KB Output is correct
5 Correct 0 ms 15748 KB Output is correct
6 Correct 0 ms 15748 KB Output is correct
7 Correct 0 ms 15748 KB Output is correct
8 Correct 0 ms 15748 KB Output is correct
9 Correct 0 ms 15748 KB Output is correct
10 Correct 0 ms 15748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 15748 KB Output is correct
2 Correct 0 ms 15748 KB Output is correct
3 Correct 0 ms 15748 KB Output is correct
4 Correct 0 ms 15748 KB Output is correct
5 Correct 0 ms 15748 KB Output is correct
6 Correct 0 ms 15748 KB Output is correct
7 Correct 0 ms 15748 KB Output is correct
8 Correct 0 ms 15748 KB Output is correct
9 Correct 0 ms 15748 KB Output is correct
10 Correct 0 ms 15748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 15748 KB Output is correct
2 Correct 0 ms 15748 KB Output is correct
3 Correct 0 ms 15748 KB Output is correct
4 Correct 0 ms 15748 KB Output is correct
5 Correct 0 ms 15748 KB Output is correct
6 Correct 0 ms 15748 KB Output is correct
7 Correct 0 ms 15748 KB Output is correct
8 Correct 0 ms 15748 KB Output is correct
9 Correct 0 ms 15748 KB Output is correct
10 Correct 0 ms 15748 KB Output is correct
11 Correct 0 ms 15748 KB Output is correct
12 Correct 0 ms 15748 KB Output is correct
13 Correct 0 ms 15748 KB Output is correct
14 Correct 0 ms 15748 KB Output is correct
15 Correct 0 ms 15748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 15748 KB Output is correct
2 Correct 0 ms 15748 KB Output is correct
3 Correct 0 ms 15748 KB Output is correct
4 Correct 0 ms 15748 KB Output is correct
5 Correct 0 ms 15748 KB Output is correct
6 Correct 0 ms 15748 KB Output is correct
7 Correct 0 ms 15748 KB Output is correct
8 Correct 0 ms 15748 KB Output is correct
9 Correct 0 ms 15748 KB Output is correct
10 Correct 0 ms 15748 KB Output is correct
11 Correct 0 ms 15748 KB Output is correct
12 Correct 0 ms 15748 KB Output is correct
13 Correct 0 ms 15748 KB Output is correct
14 Correct 0 ms 15748 KB Output is correct
15 Correct 0 ms 15748 KB Output is correct
16 Correct 0 ms 15748 KB Output is correct
17 Correct 0 ms 15748 KB Output is correct
18 Correct 0 ms 15748 KB Output is correct
19 Correct 0 ms 15748 KB Output is correct
20 Correct 0 ms 15748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 15748 KB Output is correct
2 Correct 52 ms 15748 KB Output is correct
3 Correct 44 ms 15748 KB Output is correct
4 Correct 12 ms 15748 KB Output is correct
5 Correct 48 ms 15748 KB Output is correct
6 Correct 92 ms 15748 KB Output is correct
7 Correct 56 ms 15748 KB Output is correct
8 Correct 88 ms 15748 KB Output is correct
9 Correct 64 ms 15748 KB Output is correct
10 Correct 92 ms 15748 KB Output is correct
11 Correct 72 ms 15748 KB Output is correct
12 Correct 96 ms 15748 KB Output is correct
13 Correct 88 ms 15748 KB Output is correct
14 Correct 96 ms 15748 KB Output is correct
15 Correct 100 ms 15748 KB Output is correct
16 Correct 96 ms 15748 KB Output is correct
17 Correct 88 ms 15748 KB Output is correct
18 Correct 92 ms 15748 KB Output is correct
19 Correct 88 ms 15748 KB Output is correct
20 Correct 100 ms 15748 KB Output is correct
21 Correct 88 ms 15748 KB Output is correct
22 Correct 104 ms 15748 KB Output is correct
23 Correct 92 ms 15748 KB Output is correct
24 Correct 92 ms 15748 KB Output is correct
25 Correct 88 ms 15748 KB Output is correct
26 Correct 96 ms 15748 KB Output is correct
27 Correct 104 ms 15748 KB Output is correct
28 Correct 96 ms 15748 KB Output is correct
29 Correct 108 ms 15748 KB Output is correct
30 Correct 92 ms 15748 KB Output is correct