답안 #886722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886722 2023-12-12T17:48:25 Z vjudge1 San (COCI17_san) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

#define ONLINE_JUDGE
void solve() {
    int n; 
    i64 k;
    cin >> n >> k;

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

    vector <i64> idxs[n + 2];

    int half = n / 2;

    i64 ans = 0;
    for(int mask = 1; mask < (1 << half); mask++) {
        int last = 0, lst = -1;
        i64 sum = 0;
        bool ok = true;
        for(int i = 0; i < half; i++) {
            if(mask & (1 << i)) {
                if(h[i] < last) {
                    ok = false;
                    break;
                }

                last = h[i];
                sum += g[i];

                lst = i;
            }
        }

        if(ok) {
            idxs[lst].emplace_back(sum);
            ans += (sum >= k);
        }
    }

    for(int mask = 1; mask < (1 << (n - half)); mask++) {
        int last = 0, fir = -1;
        i64 sum = 0;
        bool ok = true;
        for(int i = 0; i < (n - half); i++) {
            if(mask & (1 << i)) {
                if(h[i + half] < last) {
                    ok = false;
                    break;
                }

                last = h[i + half];
                sum += g[i + half];

                if(fir == -1) {
                    fir = half + i;
                }
            }
        }

        if(ok) {
            idxs[fir].emplace_back(sum);
            ans += (sum >= k);
        }
    }

    for(int i = 0; i < n; i++) {
        sort(idxs[i].begin(), idxs[i].end());
        /*
        cerr << i << ": ";
        for(int &j : idxs[i]) {
            cerr << j << " ";
        }
        cerr << "\n";
        */
    }

    for(int i = 0; i < half; i++) {
        for(int &j : idxs[i]) {
            for(int l = half; l < n; l++) {
                if(h[i] < h[l]) {
                    auto it = lower_bound(idxs[l].begin(), idxs[l].end(), k - j);
                    ans += idxs[l].end() - it;
                }
            }
        }
    }

    cout << ans;
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }

    return 0;
}

Compilation message

san.cpp: In function 'void solve()':
san.cpp:83:28: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   83 |         for(int &j : idxs[i]) {
      |                            ^