# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
5078 |
2014-02-02T20:35:25 Z |
ainta |
양말 찾기 (KPI13_socks) |
C++ |
|
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;
if (a / M2 != b / M2)if(p2[SZ - M2] != SZ * (a / M2) + (b / 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;
scanf("%d", &n);
while (n--){
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++){
for (j = 0; j < SZ; j++){
if (R[i][j]){
if (p1[i]) p1[i] += j - 1;
else p1[i] = j * SZ + 1;
}
if (D[i][j]){
if (p2[i]) p2[i] += j - 1;
else p2[i] = j * SZ + 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;
}
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 |
- |