Submission #5084

# Submission time Handle Problem Language Result Execution time Memory
5084 2014-02-02T21:10:03 Z ainta 양말 찾기 (KPI13_socks) C++
0 / 1
0 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 = 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]);
}
# Verdict Execution time Memory 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 Incorrect 0 ms 2140 KB Output isn't correct
10 Halted 0 ms 0 KB -