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 N 200000
int abs_(int a) { return a > 0 ? a : -a; }
int main() {
static int xx[N + 1], yy[N + 1], dd[N + 1], ll[N + 1];
int n, m, h, i, d, x, y, a, b;
scanf("%d", &n);
for (i = 1; i <= n; i++)
scanf("%d%d", &xx[i], &yy[i]);
d = 0;
for (i = 0; i < n; i++) {
x = xx[i + 1] - xx[i], y = abs_(yy[i + 1] - yy[i]);
if (y > x || (x + y) % 2 != 0) {
printf("-1\n");
return 0;
}
if (y == x && d == 0)
d = (i % 2 == 0) == (yy[i] < yy[i + 1]) ? 1 : -1;
}
if (d == 0)
d = 1;
m = 0;
for (i = 0; i <= n; i++) {
x = xx[i + 1] - xx[i], y = yy[i + 1] - yy[i];
a = (x + y) / 2, b = (x - y) / 2;
if (d == 1) {
if (a > 0) {
if (m == 0 || dd[m - 1] != 1)
dd[m++] = 1;
ll[m - 1] += a;
d = 1;
}
if (b > 0) {
if (m == 0 || dd[m - 1] != -1)
dd[m++] = -1;
ll[m - 1] += b;
d = -1;
}
} else {
if (b > 0) {
if (m == 0 || dd[m - 1] != -1)
dd[m++] = -1;
ll[m - 1] += b;
d = -1;
}
if (a > 0) {
if (m == 0 || dd[m - 1] != 1)
dd[m++] = 1;
ll[m - 1] += a;
d = 1;
}
}
}
printf("%d\n", m);
for (h = 0; h < m; h++)
printf("%d %c\n", ll[h], dd[h] == 1 ? '+' : '-');
return 0;
}
Compilation message (stderr)
Main.c: In function 'main':
Main.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
Main.c:13:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d%d", &xx[i], &yy[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |