답안 #932199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932199 2024-02-23T05:29:53 Z sleepntsheep Palembang Bridges (APIO15_bridge) C++17
22 / 100
53 ms 1984 KB
#include<stdio.h>
unsigned X=12345;int rand_(){return(X*=3)>>1;}
int abs(int a){return a<0?-a:a;}
long long minll(long long a,long long b){return a<b?a:b;}
int(*compar)(int,int);
void sort(int*aa,int l,int r){ while(l<r){int i=l,j=l,k=r,tmp,p=aa[l+rand_()%(r-l)]; while(j<k)switch(compar(aa[j],p)){case 0:++j;break;case -1:tmp=aa[j],aa[j]=aa[i],aa[i]=tmp,++i,++j;break;case 1:tmp=aa[j],aa[j]=aa[--k],aa[k]=tmp;break;}sort(aa,l,i);l=k;} }

int c0(int a,int b){return a<b?-1:a>b?1:0;}

int m,s[1<<17],t[1<<17],a[1<<18],k,n0,n;char p,q;long long z;

long long c2(int x,int y){long long z=0;for(int i=0;i<m;++i)z+=minll(abs(s[i]-y)+abs(t[i]-y),abs(s[i]-x)+abs(t[i]-x));return z;}

int main(){
    scanf("%d%d",&k,&n0);for(int w,e,i=0;i<n0;++i){scanf(" %c%d %c%d",&p,&w,&q,&e);if(p-q)s[m]=a[n++]=w,t[m++]=a[n++]=e,++z;else z+=abs(w-e);}
    compar=c0;sort(a,0,n);
    if(k==1){for(int i=0;i<n;++i)z+=abs(a[i]-a[n/2]);return printf("%lld",z),0;}

    if(m<=1000){
        long long zz=1e18;for(int i=0;i<n*n;++i)zz=minll(zz,c2(a[i/n],a[i%n]));return printf("%lld",zz+z),0;
    }
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d%d",&k,&n0);for(int w,e,i=0;i<n0;++i){scanf(" %c%d %c%d",&p,&w,&q,&e);if(p-q)s[m]=a[n++]=w,t[m++]=a[n++]=e,++z;else z+=abs(w-e);}
      |     ~~~~~^~~~~~~~~~~~~~~
bridge.cpp:15:57: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d%d",&k,&n0);for(int w,e,i=0;i<n0;++i){scanf(" %c%d %c%d",&p,&w,&q,&e);if(p-q)s[m]=a[n++]=w,t[m++]=a[n++]=e,++z;else z+=abs(w-e);}
      |                                                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 448 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 18 ms 1984 KB Output is correct
13 Correct 53 ms 1976 KB Output is correct
14 Correct 32 ms 1628 KB Output is correct
15 Correct 31 ms 1212 KB Output is correct
16 Correct 20 ms 1884 KB Output is correct
17 Correct 38 ms 1752 KB Output is correct
18 Correct 42 ms 1880 KB Output is correct
19 Correct 47 ms 1880 KB Output is correct
20 Correct 22 ms 1884 KB Output is correct
21 Correct 47 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 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 -