Submission #657992

#TimeUsernameProblemLanguageResultExecution timeMemory
657992LoboA Difficult(y) Choice (BOI21_books)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(x) x.begin(),x.end()

//
// --- Sample implementation for the task books ---
//
// To compile this program with the sample grader, place:
//     books.h books_sample.cpp sample_grader.cpp
// in a single folder and run:
//     g++ books_sample.cpp sample_grader.cpp
// in this folder.
//
const int maxn = 1e5+10;
const int maxv = 2e18+10;
int n, b[maxn];
int cnt;
int qry(int32_t i) {
    if(b[i] == 0) {
        assert(cnt--);
        return b[i] = skim(i);
    }
    return b[i];
}

int qrysum(int l, int r) {
    int sum = 0;
    for(int i = l; i <= r; i++) {
        sum+= qry(i);
        sum = min(sum,maxv);
    }
    return sum;
}
void solve(int32_t N, int32_t k, long long A, int32_t S) {
    cnt = 50;
    n = N;

    int l,r;

    l = 1;
    r = n;
    int p = -1;
    while(l <= r) {
        int mid = (l+r)/2;
        if(qry(mid) >= A) {
            r = mid-1;
            p = mid;
        }
        else {
            l = mid+1;
        }
    }

    if(p != -1) {
        if(p < k) {
            impossible();
            return;
        }
        if(qrysum(1,k-1)+qry(p) <= 2*A) {
            vector<int32_t> ans;
            for(int j = 1; j <= k-1; j++) ans.pb(j);
            ans.pb(p);
            answer(ans);
            return;
        }

        if(p == k) {
            impossible();
            return;
        }
        n = p-1;
        // n is >= k
    }

    // l = 1;
    // r = n-k+1;
    // while(l <= r) {
    //     int mid = (l+r)/2;
    //     if(qrysum(mid,mid+k-1) < A) {
    //         l = mid+1;
    //     }
    //     else if(qrysum(mid,mid+k-1) > 2*A) {
    //         r = mid-1;
    //     }
    //     else {
    //         vector<int32_t> ans;
    //         for(int j = mid; j <= mid+k-1; j++) ans.pb(j);
    //         answer(ans);
    //         return;
    //     }
    // }

    int sumcur = qrysum(1,k);
    if(sumcur > 2*A) {
        impossible();
        return;
    }
    if(sumcur >= A) {
        vector<i
        for(int j = 1; j <= k; j++) ans.pb(j);
        answer(ans);
        return;
    }

    vector<int32_t> ans;
    for(int i = k; i >= 1; i--) {
        if(sumcur-qry(i)+qry(n) < A) {
            sumcur = sumcur-qry(i)+qry(n);
            ans.pb(n);
            n--;
        }
        else if(sumcur-qry(i)+qry(n) <= 2*A) {
            //I found the answer
            ans.pb(n);
            for(int j = 1; j < i; j++) ans.pb(j);
            sort(all(ans));
            answer(ans);
            return;
        }
    }

    impossible();
}

Compilation message (stderr)

books.cpp: In function 'void solve(int32_t, int32_t, long long int, int32_t)':
books.cpp:105:16: error: 'i' was not declared in this scope
  105 |         vector<i
      |                ^
books.cpp:106:21: error: template argument 1 is invalid
  106 |         for(int j = 1; j <= k; j++) ans.pb(j);
      |                     ^
books.cpp:106:21: error: template argument 2 is invalid
books.cpp:106:24: error: 'j' was not declared in this scope
  106 |         for(int j = 1; j <= k; j++) ans.pb(j);
      |                        ^
books.cpp:107:16: error: 'ans' was not declared in this scope; did you mean 'abs'?
  107 |         answer(ans);
      |                ^~~
      |                abs