#include <stdio.h>
#include <string.h>
#define N 5000
#define M 20000
int main() {
static int ii[M], jj[M], ww[M], dd[N + 1], dd_[N + 1];
int n, m, m_, h, i, j, k, c, d;
scanf("%d%d", &n, &m);
m_ = 0;
for (i = 0; i < n; i++) {
ii[m_] = i, jj[m_] = i + 1, ww[m_] = 1, m_++;
ii[m_] = i + 1, jj[m_] = i, ww[m_] = 0, m_++;
}
while (m--) {
scanf("%d%d%d%d", &i, &j, &k, &c), j++;
if (c == 0)
ii[m_] = i, jj[m_] = j, ww[m_] = j - i - k, m_++;
else
ii[m_] = j, jj[m_] = i, ww[m_] = -(j - i + 1 - k), m_++;
}
m = m_;
for (k = 0; k <= n; k++) {
memcpy(dd_, dd, (n + 1) * sizeof *dd_);
for (h = 0; h < m; h++) {
i = ii[h], j = jj[h];
if (dd[j] > (d = dd_[i] + ww[h])) {
if (k == n) {
printf("-1\n");
return 0;
}
dd[j] = d;
}
}
}
for (i = 0; i < n; i++)
printf("%d ", dd[i + 1] - dd[i]);
printf("\n");
return 0;
}
Compilation message
restore.c: In function 'main':
restore.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
restore.c:18:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d%d%d%d", &i, &j, &k, &c), j++;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
780 KB |
Output is correct |
2 |
Correct |
131 ms |
792 KB |
Output is correct |
3 |
Correct |
100 ms |
772 KB |
Output is correct |
4 |
Correct |
95 ms |
604 KB |
Output is correct |
5 |
Correct |
306 ms |
600 KB |
Output is correct |
6 |
Correct |
322 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
780 KB |
Output is correct |
2 |
Correct |
131 ms |
792 KB |
Output is correct |
3 |
Correct |
100 ms |
772 KB |
Output is correct |
4 |
Correct |
95 ms |
604 KB |
Output is correct |
5 |
Correct |
306 ms |
600 KB |
Output is correct |
6 |
Correct |
322 ms |
604 KB |
Output is correct |
7 |
Correct |
106 ms |
856 KB |
Output is correct |
8 |
Correct |
124 ms |
604 KB |
Output is correct |
9 |
Correct |
107 ms |
604 KB |
Output is correct |
10 |
Correct |
98 ms |
604 KB |
Output is correct |
11 |
Correct |
376 ms |
800 KB |
Output is correct |
12 |
Correct |
381 ms |
808 KB |
Output is correct |
13 |
Correct |
96 ms |
852 KB |
Output is correct |
14 |
Correct |
103 ms |
856 KB |
Output is correct |
15 |
Correct |
111 ms |
804 KB |
Output is correct |
16 |
Correct |
121 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
96 ms |
780 KB |
Output is correct |
12 |
Correct |
131 ms |
792 KB |
Output is correct |
13 |
Correct |
100 ms |
772 KB |
Output is correct |
14 |
Correct |
95 ms |
604 KB |
Output is correct |
15 |
Correct |
306 ms |
600 KB |
Output is correct |
16 |
Correct |
322 ms |
604 KB |
Output is correct |
17 |
Correct |
106 ms |
856 KB |
Output is correct |
18 |
Correct |
124 ms |
604 KB |
Output is correct |
19 |
Correct |
107 ms |
604 KB |
Output is correct |
20 |
Correct |
98 ms |
604 KB |
Output is correct |
21 |
Correct |
376 ms |
800 KB |
Output is correct |
22 |
Correct |
381 ms |
808 KB |
Output is correct |
23 |
Correct |
96 ms |
852 KB |
Output is correct |
24 |
Correct |
103 ms |
856 KB |
Output is correct |
25 |
Correct |
111 ms |
804 KB |
Output is correct |
26 |
Correct |
121 ms |
604 KB |
Output is correct |
27 |
Correct |
100 ms |
808 KB |
Output is correct |
28 |
Correct |
97 ms |
600 KB |
Output is correct |
29 |
Correct |
134 ms |
604 KB |
Output is correct |
30 |
Correct |
98 ms |
856 KB |
Output is correct |
31 |
Correct |
106 ms |
800 KB |
Output is correct |
32 |
Correct |
101 ms |
604 KB |
Output is correct |
33 |
Correct |
393 ms |
816 KB |
Output is correct |
34 |
Correct |
394 ms |
812 KB |
Output is correct |
35 |
Correct |
116 ms |
816 KB |
Output is correct |
36 |
Correct |
96 ms |
812 KB |
Output is correct |