제출 #47993

#제출 시각아이디문제언어결과실행 시간메모리
47993yusufakePalembang Bridges (APIO15_bridge)C++98
31 / 100
76 ms2300 KiB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 1e5 + 5;

ll A[N],B[N],n,k,nn,t,w,i,x,y,l,m1,m2,r,ans;
char c1,c2;

ll g(ll a, ll b){
	ll t=0,i;
	for(i=1;i<=nn;i++)
		t += min( abs(a - A[i]) + abs(a - B[i]) , b == -1 ? 1LL<<55 : abs(b - A[i]) + abs(b - B[i]) ) + 1;
	return t;
}

ll f(ll a){
    if(k == 1) return g(a,-1);
    ll i, l=0,m1,m2,r=1LL<<30;
    for(i=55; i--;){
        m1 = l + (r-l)/3;
        m2 = r - (r-l)/3;
        if(g(a,m1) > g(a,m2)) l = m1;
        else r = m2;
    }
    return min( g(a,l-1) , min( g(a,l),g(a,l+1))  );
}

int main(){
    cin >> k >> n;
	for(i=1;i<=n;i++){
		scanf(" %c%d %c%d",&c1,&x,&c2,&y);
        if(c1 == c2) { ans += abs(y-x); continue; }
		A[++nn] = x; B[nn] = y;
	}

    l=0; r=1LL<<30;
	for(i=55; i--;){
		m1 = l + (r-l)/3;
        m2 = r - (r-l)/3;
		if(f(m1) > f(m2)) l = m1;
		else r = m2;
	}

    cout << ans + min( f(l-1), min( f(l) , f(l+1) ) );
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

bridge.cpp: In function 'int main()':
bridge.cpp:32:35: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'll* {aka long long int*}' [-Wformat=]
   scanf(" %c%d %c%d",&c1,&x,&c2,&y);
                          ~~       ^
bridge.cpp:32:35: warning: format '%d' expects argument of type 'int*', but argument 5 has type 'll* {aka long long int*}' [-Wformat=]
bridge.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c%d %c%d",&c1,&x,&c2,&y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...