# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
5085 | ainta | 양말 찾기 (KPI13_socks) | C++98 | 2320 ms | 2140 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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]);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |