Submission #742190

#TimeUsernameProblemLanguageResultExecution timeMemory
742190rainboyTower Defense (CEOI19_towerdefense)C11
100 / 100
1 ms292 KiB
#include <stdio.h> int abs_(int a) { return a > 0 ? a : -a; } int main() { int x1, y1, x2, y2, d, dx, dy, x, y, tmp; scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &d), dx = abs_(x2 - x1), dy = abs_(y2 - y1); if (d == dx + dy) { printf("0\n"); return 0; } if (dx + dy <= 1 || d < dx + dy || (d - (dx + dy)) % 2 != 0) { printf("impossible\n"); return 0; } d -= dx + dy, d /= 2; if (dx > 1) { if (x1 > x2) tmp = x1, x1 = x2, x2 = tmp; if (y1 > y2) tmp = y1, y1 = y2, y2 = tmp; printf("%d\n", y2 - y1 - 1 + d * 2); for (y = y1 + 1 - d; y <= y2 - 1 + d; y++) printf("%d %d\n", x1 + 1, y); return 0; } if (dy > 1) { if (x1 > x2) tmp = x1, x1 = x2, x2 = tmp; if (y1 > y2) tmp = y1, y1 = y2, y2 = tmp; printf("%d\n", x2 - x1 - 1 + d * 2); for (x = x1 + 1 - d; x <= x2 - 1 + d; x++) printf("%d %d\n", x, y1 + 1); return 0; } if (d == 1) { printf("impossible\n"); return 0; } if (x1 > x2) tmp = x1, x1 = x2, x2 = tmp, tmp = y1, y1 = y2, y2 = tmp; printf("%d\n", (d - 1) * 2); for (x = x1 + 1; x < x1 + d; x++) printf("%d %d\n", x, y1); if (y1 < y2) for (y = y1 + 1; y < y1 + d; y++) printf("%d %d\n", x1, y); else for (y = y1 - 1; y > y1 - d; y--) printf("%d %d\n", x1, y); return 0; }

Compilation message (stderr)

towerdefense.c: In function 'main':
towerdefense.c:8:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &d), dx = abs_(x2 - x1), dy = abs_(y2 - y1);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...