답안 #5085

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5085 2014-02-02T21:15:49 Z ainta 양말 찾기 (KPI13_socks) C++
1 / 1
2320 ms 2140 KB
#include<stdio.h>
#define SZ 45001
#define INF 1000000000
int n, R[3][SZ + 10], D[3][SZ + 10], p1[3], p2[3];
int PP(int a, int M1, int b, int M2){
	int i;
	for (i = a; i <= INF + INF; i += M1){
		if (i%M2 == b)break;
	}
	return i;
}
bool Correct(int a, int M1, int b, int M2){
	if (a > b){
		int t;
		t = a, a = b, b = t;
	}
	if (a / M1 != b / M1){
		if (p2[SZ - M1] != SZ * (a / M1) + (b / M1))return false;
	}
	else if (p2[SZ - M1])return false;
	if (a / M2 != b / M2){
		if (p2[SZ - M2] != SZ * (a / M2) + (b / M2))return false;
	}
	else if (p2[SZ - M2])return false;
	return true;
}
void Do(int a, int b, int M1, int c, int d, int M2){
	int i, d1, d2;
	d1 = PP(a, M1, c, M2);
	d2 = PP(b, M1, d, M2);
	if (d1 > INF * 2 || d2 > INF * 2 || !Correct(d1, M1, d2, M2)){
		d1 = PP(a, M1, d, M2);
		d2 = PP(b, M1, c, M2);
	}
	if (d1 > d2)i = d1, d1 = d2, d2 = i;
	printf("%d %d\n", d1 - INF, d2 - INF);
}
int main(){
	int i, j, a, c1, c2;
	scanf("%d", &n);
	for (j = 0; j != n; j++){
		scanf("%d", &a);
		a += INF;
		for (i = 0; i < 3; i++){
			R[i][a % (SZ - i)] = !R[i][a % (SZ - i)];
			D[i][a / (SZ - i)] = !D[i][a / (SZ - i)];
		}
	}
	for (i = 0; i < 3; i++){
		c1 = 0, c2 = 0;
		for (j = 0; j < SZ; j++){
			if (R[i][j]){
				c1++;
				if (p1[i]) p1[i] += j - 1;
				else p1[i] = j * SZ + 1;
			}
			if (D[i][j]){
				c2++;
				if (p2[i]) p2[i] += j - 1;
				else p2[i] = j * SZ + 1;
			}
		}
		if ((c1 != 0 && c1 != 2) || (c2 != 0 && c2 != 2)){
			while (1){
			}
		}
	}
	int k[6], c = 0;
	for (i = 0; i < 3 && c < 6; i++){
		if (p1[i])k[c++] = p1[i] / SZ, k[c++] = p1[i] % SZ, k[c++] = SZ - i;
	}
	if (c != 6){
		while (1){
		}
	}
	Do(k[0], k[1], k[2], k[3], k[4], k[5]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2140 KB Output is correct
2 Correct 0 ms 2140 KB Output is correct
3 Correct 0 ms 2140 KB Output is correct
4 Correct 0 ms 2140 KB Output is correct
5 Correct 0 ms 2140 KB Output is correct
6 Correct 0 ms 2140 KB Output is correct
7 Correct 0 ms 2140 KB Output is correct
8 Correct 0 ms 2140 KB Output is correct
9 Correct 0 ms 2140 KB Output is correct
10 Correct 0 ms 2140 KB Output is correct
11 Correct 2320 ms 2140 KB Output is correct
12 Correct 2272 ms 2140 KB Output is correct
13 Correct 2256 ms 2140 KB Output is correct
14 Correct 128 ms 2140 KB Output is correct
15 Correct 124 ms 2140 KB Output is correct
16 Correct 184 ms 2140 KB Output is correct
17 Correct 232 ms 2140 KB Output is correct
18 Correct 0 ms 2140 KB Output is correct
19 Correct 0 ms 2140 KB Output is correct
20 Correct 224 ms 2140 KB Output is correct
21 Correct 0 ms 2140 KB Output is correct
22 Correct 0 ms 2140 KB Output is correct
23 Correct 248 ms 2140 KB Output is correct
24 Correct 0 ms 2140 KB Output is correct
25 Correct 0 ms 2140 KB Output is correct
26 Correct 240 ms 2140 KB Output is correct
27 Correct 228 ms 2140 KB Output is correct
28 Correct 0 ms 2140 KB Output is correct
29 Correct 0 ms 2140 KB Output is correct
30 Correct 232 ms 2140 KB Output is correct
31 Correct 0 ms 2140 KB Output is correct
32 Correct 0 ms 2140 KB Output is correct
33 Correct 228 ms 2140 KB Output is correct
34 Correct 0 ms 2140 KB Output is correct
35 Correct 0 ms 2140 KB Output is correct
36 Correct 232 ms 2140 KB Output is correct
37 Correct 236 ms 2140 KB Output is correct
38 Correct 208 ms 2140 KB Output is correct
39 Correct 228 ms 2140 KB Output is correct
40 Correct 232 ms 2140 KB Output is correct
41 Correct 160 ms 2140 KB Output is correct
42 Correct 220 ms 2140 KB Output is correct
43 Correct 228 ms 2140 KB Output is correct
44 Correct 252 ms 2140 KB Output is correct
45 Correct 240 ms 2140 KB Output is correct
46 Correct 232 ms 2140 KB Output is correct
47 Correct 244 ms 2140 KB Output is correct
48 Correct 252 ms 2140 KB Output is correct
49 Correct 232 ms 2140 KB Output is correct
50 Correct 212 ms 2140 KB Output is correct