#include <stdio.h>
#define N 200000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int ii[N], jj[N];
void sort(int *hh, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = ii[hh[j]] != ii[h] ? ii[hh[j]] - ii[h] : jj[h] - jj[hh[j]];
if (c == 0)
j++;
else if (c < 0) {
tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
i++, j++;
} else {
k--;
tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
}
}
sort(hh, l, i);
l = k;
}
}
int main() {
static char cc[N + 1];
static int hh[N];
int n, h, i, cnt, ok;
scanf("%*d%d%s", &n, cc);
for (i = 0; i < n; i++)
cc[i] -= '0';
for (i = 1; i < n; i++)
cc[i] ^= cc[i - 1];
ok = cc[n - 1] == 0;
for (h = 0; h < n - 3; h++) {
int c, tmp;
scanf("%d%d%d", &ii[h], &jj[h], &c), ii[h]--, jj[h]--;
if (ii[h] > jj[h])
tmp = ii[h], ii[h] = jj[h], jj[h] = tmp;
if ((cc[jj[h] - 1] ^ (ii[h] == 0 ? 0 : cc[ii[h] - 1])) != c)
ok = 0;
hh[h] = h;
}
sort(hh, 0, n - 3);
if (n <= 2000 && 1) {
int h_;
for (h = 0; h < n - 3; h++)
for (h_ = h + 1; h_ < n - 3; h_++)
if (!(ii[h] <= ii[h_] && jj[h_] <= jj[h] || ii[h_] <= ii[h] && jj[h] <= jj[h_])
&& !(jj[h] <= ii[h_] || jj[h_] <= ii[h]) || ii[h] == ii[h_] && jj[h] == jj[h_]) {
printf("neispravna triangulacija\n");
return 0;
}
} else {
cnt = 0;
for (h = 0; h < n - 3; h++) {
int h_ = hh[h];
while (cnt && jj[hh[cnt - 1]] <= ii[h_])
cnt--;
if (cnt && (jj[h_] > jj[hh[cnt - 1]] || ii[h_] == ii[hh[cnt - 1]] && jj[h_] == jj[hh[cnt - 1]])) {
printf("neispravna triangulacija\n");
return 0;
}
hh[cnt++] = h_;
}
}
printf(ok ? "tocno\n" : "neispravno bojenje\n");
return 0;
}
Compilation message
checker.c: In function 'main':
checker.c:62:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
62 | if (!(ii[h] <= ii[h_] && jj[h_] <= jj[h] || ii[h_] <= ii[h] && jj[h] <= jj[h_])
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
checker.c:63:7: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
62 | if (!(ii[h] <= ii[h_] && jj[h_] <= jj[h] || ii[h_] <= ii[h] && jj[h] <= jj[h_])
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63 | && !(jj[h] <= ii[h_] || jj[h_] <= ii[h]) || ii[h] == ii[h_] && jj[h] == jj[h_]) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
checker.c:74:70: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
74 | if (cnt && (jj[h_] > jj[hh[cnt - 1]] || ii[h_] == ii[hh[cnt - 1]] && jj[h_] == jj[hh[cnt - 1]])) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
checker.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%*d%d%s", &n, cc);
| ^~~~~~~~~~~~~~~~~~~~~~~~
checker.c:49:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | scanf("%d%d%d", &ii[h], &jj[h], &c), ii[h]--, jj[h]--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
9 ms |
340 KB |
Output is correct |
9 |
Correct |
10 ms |
332 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
344 KB |
Output is correct |
13 |
Correct |
10 ms |
332 KB |
Output is correct |
14 |
Correct |
10 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
2704 KB |
Output is correct |
2 |
Correct |
106 ms |
2800 KB |
Output is correct |
3 |
Correct |
94 ms |
2784 KB |
Output is correct |
4 |
Correct |
96 ms |
5400 KB |
Output is correct |
5 |
Correct |
97 ms |
5812 KB |
Output is correct |
6 |
Correct |
92 ms |
5924 KB |
Output is correct |
7 |
Correct |
103 ms |
5928 KB |
Output is correct |
8 |
Correct |
97 ms |
5824 KB |
Output is correct |
9 |
Correct |
101 ms |
5828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
2752 KB |
Output is correct |
2 |
Correct |
96 ms |
2772 KB |
Output is correct |
3 |
Correct |
106 ms |
5540 KB |
Output is correct |
4 |
Correct |
104 ms |
5288 KB |
Output is correct |
5 |
Correct |
99 ms |
5448 KB |
Output is correct |
6 |
Correct |
91 ms |
2788 KB |
Output is correct |
7 |
Correct |
93 ms |
2764 KB |
Output is correct |
8 |
Correct |
117 ms |
5472 KB |
Output is correct |
9 |
Correct |
97 ms |
4932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
9 ms |
340 KB |
Output is correct |
9 |
Correct |
10 ms |
332 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
344 KB |
Output is correct |
13 |
Correct |
10 ms |
332 KB |
Output is correct |
14 |
Correct |
10 ms |
304 KB |
Output is correct |
15 |
Correct |
97 ms |
2704 KB |
Output is correct |
16 |
Correct |
106 ms |
2800 KB |
Output is correct |
17 |
Correct |
94 ms |
2784 KB |
Output is correct |
18 |
Correct |
96 ms |
5400 KB |
Output is correct |
19 |
Correct |
97 ms |
5812 KB |
Output is correct |
20 |
Correct |
92 ms |
5924 KB |
Output is correct |
21 |
Correct |
103 ms |
5928 KB |
Output is correct |
22 |
Correct |
97 ms |
5824 KB |
Output is correct |
23 |
Correct |
101 ms |
5828 KB |
Output is correct |
24 |
Correct |
97 ms |
2752 KB |
Output is correct |
25 |
Correct |
96 ms |
2772 KB |
Output is correct |
26 |
Correct |
106 ms |
5540 KB |
Output is correct |
27 |
Correct |
104 ms |
5288 KB |
Output is correct |
28 |
Correct |
99 ms |
5448 KB |
Output is correct |
29 |
Correct |
91 ms |
2788 KB |
Output is correct |
30 |
Correct |
93 ms |
2764 KB |
Output is correct |
31 |
Correct |
117 ms |
5472 KB |
Output is correct |
32 |
Correct |
97 ms |
4932 KB |
Output is correct |
33 |
Correct |
99 ms |
5908 KB |
Output is correct |
34 |
Correct |
104 ms |
5800 KB |
Output is correct |
35 |
Correct |
112 ms |
5828 KB |
Output is correct |
36 |
Correct |
99 ms |
5816 KB |
Output is correct |
37 |
Correct |
100 ms |
5868 KB |
Output is correct |
38 |
Correct |
102 ms |
5912 KB |
Output is correct |
39 |
Correct |
98 ms |
5852 KB |
Output is correct |
40 |
Correct |
92 ms |
5912 KB |
Output is correct |
41 |
Correct |
96 ms |
5916 KB |
Output is correct |
42 |
Correct |
120 ms |
6012 KB |
Output is correct |
43 |
Correct |
102 ms |
5828 KB |
Output is correct |