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 1000000
#define M 1000000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int *vv;
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k)
if (vv[ii[j]] == vv[i_])
j++;
else if (vv[ii[j]] < vv[i_]) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
sort(ii, l, i);
l = k;
}
}
int main() {
static int mem[N * 3], *ptr = mem;
static int *aa[M], *bb[M], *ii[M], hh[M], dd[N], qu[N];
static long long cc[M];
int n, m, cnt, h, i, j;
scanf("%d%d", &n, &m);
for (j = 0; j < m; j++) {
aa[j] = ptr, ptr += n;
bb[j] = ptr, ptr += n;
ii[j] = ptr, ptr += n;
}
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
scanf("%d", &aa[j][i]);
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
scanf("%d", &bb[j][i]);
for (j = 0; j < m; j++) {
for (i = 0; i < n; i++)
ii[j][i] = i;
vv = aa[j], sort(ii[j], 0, n);
}
for (i = 0; i < n; i++)
dd[i] = m;
cnt = 0;
for (j = 0; j < m; j++)
while (hh[j] < n && aa[j][i = ii[j][hh[j]]] <= cc[j]) {
if (--dd[i] == 0)
qu[cnt++] = i;
hh[j]++;
}
for (h = 0; h < cnt; h++) {
i = qu[h];
for (j = 0; j < m; j++)
cc[j] += bb[j][i];
for (j = 0; j < m; j++)
while (hh[j] < n && aa[j][i = ii[j][hh[j]]] <= cc[j]) {
if (--dd[i] == 0)
qu[cnt++] = i;
hh[j]++;
}
}
printf("%d\n", cnt);
return 0;
}
Compilation message (stderr)
Main.c: In function 'main':
Main.c:39:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:47:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d", &aa[j][i]);
| ^~~~~~~~~~~~~~~~~~~~~~
Main.c:50:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%d", &bb[j][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... |