# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
587241 |
2022-07-01T14:12:56 Z |
rainboy |
Med (COCI22_med) |
C |
|
1 ms |
300 KB |
#include <stdio.h>
#include <string.h>
#define N 500
#define L 10
#define S 500
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
char ss[N][L + 1]; int aa[N], ii[N];
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) {
int c = aa[ii[j]] != aa[i_] ? aa[i_] - aa[ii[j]] : strcmp(ss[ii[j]], ss[i_]);
if (c == 0)
j++;
else if (c < 0) {
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 ll[N], rr[N];
int n, h, i, l, r;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", ss[i]);
for (h = 0; h < 5; h++) {
int a;
scanf("%d", &a);
aa[i] += a;
}
ii[i] = i;
}
sort(ii, 0, n);
for (i = 0, l = 0, r = 0; i < n; i++) {
while (aa[ii[l]] - aa[ii[i]] > S || aa[ii[l]] - aa[ii[i]] == S && strcmp(ss[ii[l]], ss[ii[i]]) < 0)
l++;
while (r < n && (aa[ii[i]] - aa[ii[r]] < S || aa[ii[i]] - aa[ii[r]] == S && strcmp(ss[ii[i]], ss[ii[r]]) > 0))
r++;
ll[ii[i]] = l + 1, rr[ii[i]] = r;
}
for (i = 0; i < n; i++)
printf("%d %d\n", ll[i], rr[i]);
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:55:66: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
55 | while (aa[ii[l]] - aa[ii[i]] > S || aa[ii[l]] - aa[ii[i]] == S && strcmp(ss[ii[l]], ss[ii[i]]) < 0)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:57:76: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
57 | while (r < n && (aa[ii[i]] - aa[ii[r]] < S || aa[ii[i]] - aa[ii[r]] == S && strcmp(ss[ii[i]], ss[ii[r]]) > 0))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:42:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
Main.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%s", ss[i]);
| ^~~~~~~~~~~~~~~~~~
Main.c:48:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d", &a);
| ^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
292 KB |
Output is correct |