#include <stdio.h>
#define N 100000
#define T 3
#define S 6
int min(int a, int b) { return a < b ? a : b; }
int pref[S][T] = {
{ 0, 1, 2 },
{ 0, 2, 1 },
{ 1, 0, 2 },
{ 1, 2, 0 },
{ 2, 0, 1 },
{ 2, 1, 0 }
};
int main() {
static int ii[T][N], ii_[N], ep[N][T], eo[N], kk[N], ll[N], mm[S];
int n, g, h, i, j, j_, p, q, s, t, t_;
scanf("%d", &n);
for (t = 0; t < T; t++)
for (i = 0; i < n; i++) {
scanf("%d", &p), p--;
ii[p][t] = i;
}
for (p = 0; p < n; p++) {
ii_[p] = n;
for (t = 0; t < T; t++)
ii_[p] = min(ii_[p], ii[p][t]);
}
for (p = 0; p < n; p++) {
i = ii_[p];
ep[i][eo[i]++] = p;
}
for (i = 0; i < n; i++)
for (g = 0; g < eo[i]; g++)
for (h = g + 1; h < eo[i]; h++) {
p = ep[i][g], q = ep[i][h], j_ = n, t_ = -1;
for (t = 0; t < T; t++)
if (ii[p][t] == i || ii[q][t] == i) {
j = i ^ ii[p][t] ^ ii[q][t];
if (j_ > j)
j_ = j, t_ = t;
}
kk[t_]++;
if (ii[p][t_] < ii[q][t_])
ll[p]++;
else
ll[q]++;
}
for (i = n - 1; i >= 0; i--) {
for (g = 0; g < eo[i]; g++) {
p = ep[i][g];
for (s = 0; s < S; s++) {
for (t = 0; t < T; t++)
if (ii[p][pref[s][t]] == i)
break;
kk[pref[s][t]] += mm[s], ll[p] += mm[s];
}
}
for (g = 0; g < eo[i]; g++) {
p = ep[i][g];
for (s = 0; s < S; s++) {
int congruent = 1;
for (t = 1; t < T; t++)
if (ii[p][pref[s][t - 1]] > ii[p][pref[s][t]] || ii[p][pref[s][t - 1]] == ii[p][pref[s][t]] && pref[s][t - 1] > pref[s][t]) {
congruent = 0;
break;
}
if (congruent)
mm[s]++;
}
}
}
for (t = 0; t < T; t++)
printf("%d ", kk[t]);
printf("\n");
for (p = 0; p < n; p++)
printf("%d ", ll[p]);
printf("\n");
return 0;
}
Compilation message
tenis.c: In function 'main':
tenis.c:69:98: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
69 | if (ii[p][pref[s][t - 1]] > ii[p][pref[s][t]] || ii[p][pref[s][t - 1]] == ii[p][pref[s][t]] && pref[s][t - 1] > pref[s][t]) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tenis.c:22:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
tenis.c:25:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%d", &p), p--;
| ^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |