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 100000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int xx[N * 2];
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 (xx[ii[j]] == xx[i_])
j++;
else if (xx[ii[j]] < xx[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 ii[N * 2];
int k, n, n_, i;
long long ans;
scanf("%d%d", &k, &n);
ans = 0, n_ = 0;
for (i = 0; i < n; i++) {
static char s[2], t[2];
int l, r, tmp;
scanf("%s%d%s%d", s, &l, t, &r);
if (s[0] == t[0]) {
ans += r - l;
continue;
}
if (l > r)
tmp = l, l = r, r = tmp;
xx[n_ * 2 + 0] = l, xx[n_ * 2 + 1] = r, n_++;
}
n = n_;
ans += n;
if (k == 1) {
for (i = 0; i < n * 2; i++)
ii[i] = i;
sort(ii, 0, n * 2);
for (i = 0; i < n * 2; i++)
ans += xx[ii[i]] * (i < n ? -1 : 1);
printf("%lld\n", ans);
return 0;
}
printf(":(\n");
return 0;
}
Compilation message (stderr)
bridge.c: In function 'main':
bridge.c:37:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
37 | scanf("%d%d", &k, &n);
| ^~~~~~~~~~~~~~~~~~~~~
bridge.c:43:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
43 | scanf("%s%d%s%d", s, &l, t, &r);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |