Submission #1286707

#TimeUsernameProblemLanguageResultExecution timeMemory
1286707user736482A Difficult(y) Choice (BOI21_books)C++20
Compilation error
0 ms0 KiB

void solve(int a,int b,long long c,int d);
/*
SAMPLE GRADER for task BOOKS

USAGE:
place together with your solution and books.h in the same directory, then:
g++ <flags> sample_grader.cpp <solution_file>
e.g.:
g++ -std=c++17 sample_grader.cpp books.cpp

INPUT/OUTPUT:
The sample grader expects on standard input two lines. The first line should
contain the four integers N, K, A and S. The second line should contain a list
of N integers, the sequence of difficulties x_1 x_2 ... x_N which has to be
strictly increasing. Then, the grader writes to standard output a protocol of
all grader functions called by your program.
At the end, the grader prints your verdict.
*/
#include<vector>
#include<cstdio>
#include<set>
#include<cstdlib>
#include<cstdarg>


using namespace std;

typedef long long ll;

void __attribute__((noreturn)) __attribute__((format(printf, 1, 2))) result(const char *msg, ...)
{
    va_list args;
    va_start(args, msg);
    vfprintf(stderr, msg, args);
    fprintf(stderr, "\n");
    va_end(args);
    exit(0);
}

namespace
{
    int N, K, S, sUsed;
    long long A;
    vector<long long> seq;
}

void impossible()
{
    result("Impossible (not checked): %d book(s) skimmed", sUsed);
    exit(0);
}

long long skim(int pos)
{
    printf("skim(%d): ", pos);
	if (pos<1 || pos>N) result("Invalid skim");
    printf("%lld\n", seq[pos]);
	sUsed++;
	if (sUsed>S) result("Out of books to skim");
    return seq[pos];
}

void answer(vector<int> v)
{
    printf("answer({");
    for(int i = 0; i < (int) v.size(); ++i)
    {
        printf("%d", v[i]);
        if(i + 1 != (int) v.size()) printf(", ");
    }
    printf("})\n");

	if ((int) v.size() != K) result("Invalid answer");
   	ll sum = 0;
	for(auto x: v) {
		if (x<1 || x>N) result("Invalid answer");
		sum += seq[x];
	}	
	if (sum < A || 2*A<sum) result("Wrong answer");

	result("Correct: %d book(s) skimmed", sUsed);
    exit(0);
}


int main()
{
    if(scanf("%d %d %lld %d", &N, &K, &A, &S) != 4)
        result("Invalid input");

    seq.resize(N + 1);
    for(int i = 1; i <= N; ++i) {
    	if(scanf("%lld", &(seq[i])) != 1) result("Invalid input");
		if(i>1 && seq[i]<=seq[i-1]) result("Invalid input");
   	}

    solve(N, K, A, S);

    result("No answer");
}







#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define MOD 998244353LL
#define INF 1000000001LL
#define POT (1LL<<20)
#define INFL 1000000000000000099LL
#define pii pair<ll,ll>
#define ppi pair<pii,ll>
#define pip pair<ll,pii>
#define ppp pair<pii,pii>
#define vi vector<ll>
#define vii vector<pii>
#define al(x) x.begin(),x.end()
#define rev(x) reverse(al(x))
#define X 18
template<typename T, typename U>
pair<T, U> operator+(const pair<T, U>& a, const pair<T, U>& b) {
    return {a.first + b.first, a.second + b.second};
}
template<typename T, typename U>
pair<T, U> operator-(const pair<T, U>& a, const pair<T, U>& b) {
    return {a.first - b.first, a.second - b.second};
}
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os<<"{"<<p.ff<<", "<<p.ss<<"}";
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    for (size_t i = 0; i < v.size(); ++i) {
        if (i) os << ", ";
        os << v[i];
    }
    os << "}";
    return os;
}
void solve(int N,int K,ll a,int S){
    ll n=N;
    ll k=K;
    ll s=S;
    vi v;
    ll b=0;
    for(ll i=1;i<k;i++){
        v.pb(skim(i));
        b+=v.back();
    }
    ll pocz=k;
    ll kon=n+1;
    ll x,y=INFL;
    while(pocz!=kon){
        ll md=(pocz+kon)/2;
        x=skim(md);
        if(b+x<a)pocz=md+1;
        else {kon=md;y=x;}
    }
    if(b+y<=2*a){
        vector<int>ans;
        for(ll i=1;i<k;i++)ans.pb(i);
        ans.pb(pocz);
        answer(ans);return;
    }
    x=pocz-1;
    if(x<k){
        impossible();return;
    }
    vector<int>ans;
    v.pb(0);
    for(ll i=1;i<=k;i++){
        ans.pb(x);
        b+=skim(x);
        b-=v[v.size()-i]; 
        x--;
        if(b>=a){
            for(ll j=1;j<=k-i;j++)ans.pb(j); 
            answer(ans);
        }
    }
    impossible();
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccgareyE.o: in function `answer(std::vector<int, std::allocator<int> >)':
grader.cpp:(.text+0xa0): multiple definition of `answer(std::vector<int, std::allocator<int> >)'; /tmp/ccimMWBX.o:books.cpp:(.text+0x2e0): first defined here
/usr/bin/ld: /tmp/ccgareyE.o: in function `impossible()':
grader.cpp:(.text+0x160): multiple definition of `impossible()'; /tmp/ccimMWBX.o:books.cpp:(.text+0x230): first defined here
/usr/bin/ld: /tmp/ccgareyE.o: in function `skim(int)':
grader.cpp:(.text+0x1a0): multiple definition of `skim(int)'; /tmp/ccimMWBX.o:books.cpp:(.text+0x250): first defined here
/usr/bin/ld: /tmp/ccgareyE.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccimMWBX.o:books.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status