답안 #142879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
142879 2019-08-11T22:03:54 Z Ort San (COCI17_san) C++11
24 / 120
1000 ms 384 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MEM(a, b) memset(a, (b), sizeof(a))
#define ALL(c) (c).begin(),(c).end()
#define ll long long
#define LINF (ll)1e18
#define INF (int)1e9
#define pb push_back
#define sz(a) ((int)(a.size()))
#define mp make_pair
#define MOD 1000000007
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAX 200005
#define N 21

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int n, fh, sh;
ll k, hi, gi, sol, curr, sum;
ll h[N], g[N];
map<ll, vector<ll> > M;
vector<pll> one;
bool flag;

int main() {
	cin >> n >> k;
	fh = n>>1;
	sh = n-fh;
	for(int i=0;i<n;i++) {
		cin >> h[i] >> g[i];
	}
	for(int i=1;i<(1<<fh);i++) {
		curr = 0; sum = 0; flag = 0;
		for(int j=0;j<fh;j++) {
			if((i>>j)&1) {
				if(h[j]>=curr) {
					curr = h[j]; sum += g[j];
				}
				else {
					flag = 1; break;
				}
			}
		}
		if(sum>=k && !flag) sol++;
		if(flag) {continue;}
		one.pb(mp(sum,curr));
	}
	for(int i=1;i<(1<<sh);i++) {
		curr = 0; sum = 0; flag = 0;
		for(int j=0;j<sh;j++) {
			if((i>>j)&1) {
				if(h[j+fh]>=curr) {
					curr = h[j+fh]; sum += g[j+fh];
				}
				else {
					flag = 1; break;
				}
			}
		}
		if(sum>=k && !flag) sol++;
		if(flag) {continue;}
		M[curr].pb(sum);
	}
	for(auto &it:M) sort(it.second.begin(), it.second.end());
	for(int i=0;i<sz(one);i++) {
		sum = one[i].first; curr = one[i].second;
		for(auto it = M.begin();it!=M.end();it++) {
			ll id = it->first; ll siz = it->second.size();
			if(curr>id) continue;
			sol += (it->second.end()-(lower_bound(ALL(it->second), k-sum)));
		}
	}
	cout << sol;
	return 0;
}

Compilation message

san.cpp: In function 'int main()':
san.cpp:74:26: warning: unused variable 'siz' [-Wunused-variable]
    ll id = it->first; ll siz = it->second.size();
                          ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1074 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1062 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1071 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -