# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
165166 |
2019-11-25T12:48:47 Z |
sans |
San (COCI17_san) |
C++14 |
|
135 ms |
7656 KB |
#include <iostream>
#include <numeric>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 13;
const int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;
const int MAXN = 42;
int n, h[MAXN], g[MAXN];
ll k;
vector<int> hs;
vll L[MAXN], R[MAXN];
void rec_left(int pos, int last, ll sum){
if(pos == n/2){
int idx = lower_bound(hs.begin(), hs.end(), last) - hs.begin();
L[idx].pb(sum);
return;
}
rec_left(pos+1, last, sum);
if(h[pos] >= last)
rec_left(pos+1, h[pos], sum + g[pos]);
}
void rec_right(int pos, int first, int last, ll sum){
if(pos == n){
int idx = lower_bound(hs.begin(), hs.end(), first) - hs.begin();
R[idx].pb(sum);
return;
}
rec_right(pos+1, first, last, sum);
if(h[pos] >= last){
int nfirst = (first == 0) ? h[pos] : first;
rec_right(pos+1, nfirst, h[pos], sum + g[pos]);
}
}
int main(int argc, char **argv){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n >> k;
for(int i = 0; i < n; ++i){
cin >> h[i] >> g[i];
hs.pb(h[i]);
}
hs.pb(0);
sort(hs.begin(), hs.end());
rec_left(0, 0, 0);
rec_right(n/2, 0, 0, 0);
ll ans = 0;
for(int i = 0; i < (int)hs.size(); ++i)
sort(R[i].begin(), R[i].end());
for(int i = 0; i < (int)hs.size(); ++i){
for(auto it: L[i]){
ans += R[0].end() - lower_bound(R[0].begin(), R[0].end(), k-it);
for(int j = i; j < (int)hs.size(); ++j)
ans += R[j].end() - lower_bound(R[j].begin(), R[j].end(), k-it);
}
}
cout << ans << endl;
return 0;
}
//cikisir
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
1308 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
2080 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
7656 KB |
Output is correct |
2 |
Correct |
20 ms |
1712 KB |
Output is correct |