답안 #37243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
37243 2017-12-23T03:39:19 Z huynhsmd San (COCI17_san) C++14
48 / 120
1000 ms 34872 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
ll n,k,ans=0;
pair<ll,ll> a[50];
vector < pair<ll, ll> > data[2];
void bt1(ll start, ll end,ll val,ll high){
	if(start==end+1)
		{
			data[0].pb(mp(high,val));
			return ;
		}
	if(a[start].fi>=high)	
	{
		val+=a[start].se;
		bt1(start+1,end,val,a[start].fi);
		val-=a[start].se;
		bt1(start+1,end,val,high);	
	}
	else 
		bt1(start+1,end,val,high);		
			
}
void bt2(ll start, ll end,ll val,ll high){
	if(start==end+1)
		{
			data[1].pb(mp(high,val));
			return ;
		}
	if(a[end].fi<=high)	
	{
		val+=a[end].se;
		bt2(start,end-1,val,a[end].fi);
		val-=a[end].se;
		bt2(start,end-1,val,high);	
	}
	else 
		bt2(start,end-1,val,high);		
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i].fi>>a[i].se;
	bt1(1,n/2,0,0);
	bt2(n/2+1,n,0,1000000009);
	sort(data[1].begin(),data[1].end());
	for(int i=0;i<data[0].size();i++)
		{
			ll pos=lower_bound(data[1].begin(),data[1].end(),mp(data[0][i].fi,0LL))-data[1].begin();
			for(int j=pos;j<data[1].size();j++)
				if(data[0][i].se+data[1][j].se>=k)
					ans++;		
		}	
	cout<<ans;	
}

Compilation message

san.cpp: In function 'int main()':
san.cpp:52:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<data[0].size();i++)
               ^
san.cpp:55:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=pos;j<data[1].size();j++)
                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2016 KB Output is correct
2 Correct 0 ms 2016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2016 KB Output is correct
2 Correct 0 ms 2016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 4152 KB Execution timed out
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 9272 KB Execution timed out
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 34872 KB Execution timed out
2 Halted 0 ms 0 KB -