Go to diff to previous submission
#include <stdio.h> #include <math.h> int R,C, Lr, Lc, Gr, Gc; int get_dist(int a, int b, int x, int y) { } int main() { { int d = get_dist(Gr, Gc, Lr, Lc); int result = 0; if (d == 0) { } else if (R == 1 || C == 1) { } else if (R == 2 || C == 2) { if (d % 3 == 0) { } else if (x*2 < y) { result = y/2; result += (y%2 > 0) ? 1 : 0; } else if (y*2 < x) { result = x/2; result += (x%2 > 0) ? 1 : 0; } else { switch(d) { case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; } if (d > 5) { result += (d % 3) > 0 ? 1 : 0; result += d/3; } } } return 0; }
--- c4.s685.cteam074.grasshop.c.0.grasshop.c +++ c4.s755.cteam074.grasshop.c.0.grasshop.c @@ -14,4 +14,7 @@ { int d = get_dist(Gr, Gc, Lr, Lc); + int x = fabs(Gr-Lr); + int y = fabs(Gc-Lc); + int result = 0; if (d == 0) { printf("0\n"); @@ -22,6 +25,14 @@ else if (R == 2 || C == 2) { if (d % 3 == 0) { - printf("%d\n", d/3); + printf("%d\n", d/2); } else printf("impossible\n"); + } else if (x*2 < y) { + result = y/2; + result += (y%2 > 0) ? 1 : 0; + printf("%d\n", result); + } else if (y*2 < x) { + result = x/2; + result += (x%2 > 0) ? 1 : 0; + printf("%d\n", result); } else { switch(d) { @@ -43,5 +54,5 @@ } if (d > 5) { - int result = (d % 3) > 0 ? 1 : 0; + result += (d % 3) > 0 ? 1 : 0; result += d/3; printf("%d\n", result);