답안 #473647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
473647 2021-09-15T19:10:43 Z _L__ San (COCI17_san) C++17
0 / 120
1000 ms 10580 KB
// This code is written by _L__
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define F_word ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
typedef long long ll;
typedef long double ld;
const ll mod = 1e9+7, N = 5e5+13, inf = 1e11;
const ld E = 1e-6;
#define ff first
#define ss second

int main(void){
    F_word;
    ll n, k; cin >> n >> k; ll h1[n/2], h2[n-(n/2)], c1[n/2], c2[n-(n/2)];
    for(int i = 0; i < n; ++i){
        if(i < (n/2)) cin >> h1[i] >> c1[i];
        else cin >> h2[i-(n/2)] >> c2[i-(n/2)];
    }
    int q1 = n/2, q2 = n-(n/2);
    vector<pair<ll, ll>> v;
    for(int i = 0; i < (1<<q1); ++i){
        bool valid = 1; ll last = 0, sum = 0;
        for(int j = 0; j < q1; ++j){
            if(!(i&(1<<j))) continue;
            if(h1[j] >= last){sum += c1[j]; last = h1[j];}
            else{valid = 0; break;}
        }
        if(valid) v.push_back({last, sum});
    }
    sort(v.begin(), v.end());
    map<ll, vector<ll>> mp;
    for(int i = 0; i < (1<<q2); ++i){
        bool valid = 1; ll last = 0, fi = inf, sum = 0;
        for(int j = 0; j < (q2); ++j){
            if(!(i&(1<<j)))continue;
            if(fi == inf) fi = h2[j];
            if(h2[j] >= last){last = h2[j]; sum += c2[j];}
            else{valid = 0; break;}
        }
        if(valid) mp[fi].push_back(sum);
    }
    ll ans = 0;
    for(auto i: mp) sort(i.ss.begin(), i.ss.end());
    for(auto u: v){
        for(auto i: mp){
            if(i.ff >= u.ff){
                ll z = lower_bound(i.ss.begin(), i.ss.end(), max(k-u.ss, 0ll))-i.ss.begin();
                ans += max((ll)i.ss.size()-z, 0ll);
            }
        }
    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 799 ms 1568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1043 ms 2632 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1093 ms 10580 KB Time limit exceeded
2 Halted 0 ms 0 KB -