제출 #34853

#제출 시각아이디문제언어결과실행 시간메모리
34853szawinisSan (COCI17_san)C++14
120 / 120
239 ms4800 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int n, h[42], g[42];
ll k, ans;
vector<ll> f[22];
int main() {
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> h[i] >> g[i];
	h[0] = INT_MIN; h[n+1] = INT_MAX;
	for(int mask = 0; mask < 1 << n/2; mask++) {
		int pre = 0;
		ll sum = 0;
		bool valid = true;
		for(int i = 1; i <= n/2; i++) if(mask >> i-1 & 1) {
			sum += g[i];
			valid &= !pre || h[i] >= h[pre];
			pre = i;
		}
		if(valid) f[pre].push_back(sum);
	}
	for(int i = 0; i <= n/2; i++) sort(f[i].begin(), f[i].end());
	for(int mask = 0; mask < 1 << (n+1)/2; mask++) {
		int pre = n+1;
		ll sum = 0;
		bool valid = true;
		for(int i = n; i >= n/2+1; i--) if(mask >> i-n/2-1 & 1)	{
			sum += g[i];
			valid &= pre == n+1 || h[i] <= h[pre];
			pre = i;
		}
		if(valid) for(int i = 0; i <= n/2; i++) if(h[i] <= h[pre]) {
			auto it = lower_bound(f[i].begin(), f[i].end(), k - sum);
			ans += f[i].end() - it;
		}
	}
	cout << ans;
}

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

san.cpp: In function 'int main()':
san.cpp:16:45: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   for(int i = 1; i <= n/2; i++) if(mask >> i-1 & 1) {
                                             ^
san.cpp:28:51: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   for(int i = n; i >= n/2+1; i--) if(mask >> i-n/2-1 & 1) {
                                                   ^
#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...