#include <stdio.h>
#include <stdlib.h>
#define MAX_N 2000000
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int cmpr(const void*a,const void*b){return *(const int*)a - *(const int*)b;}
int n, k, a[MAX_N], b[MAX_N], c[MAX_N<<1], o, p;
long long cost;
int main()
{
scanf("%d%d", &k, &n);
for (int s, t, i = 0; i < n; ++i)
{
char bb, cc;
scanf(" %c%d %c%d",&bb,&s,&cc,&t);
if(bb==cc) cost += abs(t-s);
else
{
a[o] = min(s, t);
b[o] = max(s, t);
c[p++] = s; c[p++] = t;
++o;
}
}
if(k==1)
{
qsort(c, p, sizeof*c, cmpr);
for(int j=0;j<p;++j)
cost += abs(c[p/2] - c[j]);
printf("%lld\n", cost);
}
}
Compilation message
bridge.c: In function 'main':
bridge.c:14:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d%d", &k, &n);
| ^~~~~~~~~~~~~~~~~~~~~
bridge.c:18:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf(" %c%d %c%d",&bb,&s,&cc,&t);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
4532 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |