Submission #17345

# Submission time Handle Problem Language Result Execution time Memory
17345 2015-11-22T08:46:14 Z comet Palembang Bridges (APIO15_bridge) C++
0 / 100
0 ms 4240 KB
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

int K,N;
ll base;
ll a[200010],sum[200010],sz;

int main(){
	scanf("%d%d ",&K,&N);
	char tx,ty;
	ll x,y;
	for(int i=0;i<N;i++){
		scanf("%c %lld %c %lld ",&tx,&x,&ty,&y);
		//printf("%c %lld %c %lld\n",tx,x,ty,y);
		if(tx==ty){
			base+=abs(x-y);
		}else{
			a[++sz]=x;
			a[++sz]=y;
			base++;
		}
	}

	sort(a+1,a+sz+1);
	a[sz+1]=-1;

	for(int i=1;i<=sz;i++){
		sum[i]=sum[i-1]+a[i];
	}

	ll ans=1e18;

	for(ll i=1;i<=sz;i++){
		x=a[i];
		while(i<=sz&&a[i+1]==x)i++;

		//printf("%lld %d ")

		ans=min(ans,sum[sz]-2ll*sum[i]+(2ll*i-sz)*x);
	}
	printf("%lld",ans+base);

}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:11:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d ",&K,&N);
                      ^
bridge.cpp:15:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%c %lld %c %lld ",&tx,&x,&ty,&y);
                                          ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 4240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 4240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 4240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 4240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 4240 KB Output isn't correct
2 Halted 0 ms 0 KB -