답안 #992452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
992452 2024-06-04T13:22:40 Z LOLOLO San (COCI17_san) C++14
120 / 120
100 ms 6896 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (ll)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 50;
ll h[N], g[N], ans = 0, n, k;
vector <ll> lst[N];
vector <int> ed[N];

void dfs(int cur, int st, ll sum) {
    lst[st].pb(sum);
    if (sum >= k) {
        ans++;
    }

    for (auto x : ed[cur]) {
        dfs(x, st, sum + g[x]);
    }
}

ll cal(int a, int b) {
    ll ans = 0;
    for (auto x : lst[a]) {
        ll t = lower_bound(all(lst[b]), k - x) - lst[b].begin();
        ans += (sz(lst[b]) - t);
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;

    for (int i = 1; i <= n; i++) {
        cin >> h[i] >> g[i];
    }

    int m = n / 2;
    for (int i = 1; i <= m; i++) {
        for (int j = i + 1; j <= m; j++) {
            if (h[j] >= h[i]) {
                ed[j].pb(i);
            }
        }
    }

    for (int i = m + 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (h[j] >= h[i]) {
                ed[i].pb(j);
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        dfs(i, i, g[i]);
        sort(all(lst[i]));
    }

    for (int i = 1; i <= m; i++) {
        for (int j = m + 1; j <= n; j++) {
            if (h[j] >= h[i]) {
                ans += cal(i, j);
            }
        }
    }

    cout << ans << '\n';

    return 0;
}  
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1400 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 1876 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 6896 KB Output is correct
2 Correct 15 ms 1816 KB Output is correct