답안 #107214

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107214 2019-04-22T13:45:52 Z nxteru Palembang Bridges (APIO15_bridge) C++14
100 / 100
131 ms 6884 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PB push_back
struct t{
	ll a,b;
	bool operator<(const t&q)const{
		return a+b<q.a+q.b;
	}
};
struct mid{
	priority_queue<ll>d;
	priority_queue<ll,vector<ll>,greater<ll> >u;
	ll ds,us;
	void ini(void){
		ds=0,us=0;
		while(!d.empty())d.pop();
		while(!u.empty())u.pop();
	}
	void pushd(ll x){
		d.push(x);
		ds+=x;
	}
	void pushu(ll x){
		u.push(x);
		us+=x;
	}
	ll popd(void){
		ll res=d.top();
		d.pop();
		ds-=res;
		return res;
	}
	ll popu(void){
		ll res=u.top();
		u.pop();
		us-=res;
		return res;
	}
	void push(ll x){
		if(u.size()==0||u.top()<=x)pushu(x);
		else pushd(x);
		while(u.size()>d.size()+1)pushd(popu());
		while(u.size()<d.size())pushu(popd());
	}
	ll que(void){
		ll res=us-ds;
		if(u.size()>d.size())res-=u.top();
		return res;
	}
};
int n,k;
ll s,l[100005],r[100005];
vector<t>p;
mid q;
int main(void){
    scanf("%d%d",&k,&n);
    for(int i=0;i<n;i++){
		char x,y;
		ll a,b;
		scanf(" %c %lld %c %lld",&x,&a,&y,&b);
		if(x==y)s+=abs(a-b);
		else{
			p.PB(t{a,b});
			s++;
		}
	}
	n=p.size();
	sort(p.begin(),p.end());
	q.ini();
	for(int i=0;i<n;i++){
		q.push(p[i].a);
		q.push(p[i].b);
		l[i]=q.que();
	}
	q.ini();
	for(int i=n-1;i>=0;i--){
		q.push(p[i].a);
		q.push(p[i].b);
		r[i]=q.que();
	}
	ll ans=r[0];
	for(int i=0;i<n;i++)ans=min(ans,l[i]+r[i+1]);
	if(k==1)printf("%lld\n",l[n-1]+s);
	else printf("%lld\n",ans+s);
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&k,&n);
     ~~~~~^~~~~~~~~~~~~~
bridge.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c %lld %c %lld",&x,&a,&y,&b);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 356 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 412 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 58 ms 6368 KB Output is correct
13 Correct 131 ms 6372 KB Output is correct
14 Correct 92 ms 5608 KB Output is correct
15 Correct 59 ms 4076 KB Output is correct
16 Correct 66 ms 6740 KB Output is correct
17 Correct 111 ms 6492 KB Output is correct
18 Correct 85 ms 6500 KB Output is correct
19 Correct 90 ms 6456 KB Output is correct
20 Correct 61 ms 6500 KB Output is correct
21 Correct 110 ms 6432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 380 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 256 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 3 ms 356 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 304 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 58 ms 6372 KB Output is correct
26 Correct 83 ms 6376 KB Output is correct
27 Correct 119 ms 6632 KB Output is correct
28 Correct 112 ms 6580 KB Output is correct
29 Correct 118 ms 6372 KB Output is correct
30 Correct 54 ms 3180 KB Output is correct
31 Correct 52 ms 6372 KB Output is correct
32 Correct 81 ms 6372 KB Output is correct
33 Correct 125 ms 6884 KB Output is correct
34 Correct 111 ms 6372 KB Output is correct
35 Correct 87 ms 6372 KB Output is correct
36 Correct 99 ms 6376 KB Output is correct
37 Correct 51 ms 6372 KB Output is correct