답안 #473525

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
473525 2021-09-15T16:03:10 Z _L__ San (COCI17_san) C++17
0 / 120
1000 ms 14628 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 = 1e9+1;
const ld E = 1e-6;
#define ff first
#define ss second

int main(void){
    F_word;
    ll n, k; cin >> n >> k;
    ll h[n] = {}, c[n]= {};
    ll ans = 0;
    int x = n/2; int b = (n-(n/2));
    for(int i = 0; i < n; ++i) cin >> h[i] >> c[i];
    vector<pair<ll, ll>> fbi;
    for(int i = 0; i < (1<<x); ++i){
        ll hg = 0, gg = 0;
        for(int j = 0; j < x; ++j){
            if(i&(1<<j)){
                if(hg <= h[j]){hg = h[j], gg += c[j];}
                else break;
            }
        }
        fbi.push_back({hg, gg});
        ans += (gg >= k);
    }
    map<ll, vector<ll>> mp;
    for(int i = 0; i < (1<<b); ++i){
        ll hg = 0, gg = 0;
        for(int j = 0; j < b; ++j){
            if(i&(1<<j)){
                if(hg <= h[j+x]){hg = h[j+x]; gg += c[j+x];}
                else {gg = -1; break;}
            }
        }
        if(gg == -1) continue;
        ans += (gg >= k);
        for(int j = 0; j < b; ++j){
            if(i&(1<<j)){
                mp[h[j+x]].push_back(gg);
                break;
            }
        }
    }
    for(auto i: mp)sort(i.ss.begin(), i.ss.end());
    for(auto u: fbi){
        for(auto i: mp){
            if(i.ff >= u.ff){
                ll f = lower_bound(i.ss.begin(), i.ss.end(), k-u.ss)-i.ss.begin();
                ans += i.ss.size()-f;
            }
        }
    }
    cout << ans << endl;
} 
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 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 801 ms 1576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 5952 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 14628 KB Time limit exceeded
2 Halted 0 ms 0 KB -