답안 #145217

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145217 2019-08-19T10:11:14 Z mat_v Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
#include <cstdio>
#include <vector>
#include <cassert>
#include <bits/stdc++.h>
#include "molecules.h"
#define maxn 200005
using namespace std;
typedef long long ll;

int n;
ll pref[maxn];
ll suff[maxn];
int a,b;
bool dobar(ll x){
    if(x >=a && x<=b)return 1;
    return 0;
}
std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    sort(w.begin(), w.end());
    n = w.size();
    ll tren = 0;
    a = l;
    b = u;
    for(int i=0; i<n; i++){
        tren += w[i];
        pref[i + 1] = tren;
    }
    if(dobar(pref[n])){
        vector<int> rez;
        for(int i=0; i<n; i++)rez.push_back(i);
        return rez;
    }
    vector<int>v;
    if(pref[n] < l)return v;
    tren = 0;
    for(int i=n-1; i>=0; i--){
        tren += w[i];
        suff[n - i] = tren;
    }
    int levo = n,d = 0;
    bool ima = 0;
    for(int i=0; i<=n; i++){
        ll sum = suff[i];
        d = i;
        if(sum > u)break;
        if(dobar(sum + pref[levo])){
            ima = 1;
            break;
        }
        while(sum + pref[levo] > u){
            if(dobar(sum  + pref[levo])){
                ima = 1;
                break;
            }
            levo--;
        }
        if(ima)break;
        if(dobar(sum + pref[levo])){
            ima = 1;
            break;
        }
    }
    vector<int>rez;
    if(!ima){
        return rez;
    }
    int koji = n - d;
    for(int i=1; i<=levo; i++)rez.push_back(i-1);
    for(int i=n-1; i>=koji; i--)rez.push_back(i);
    return rez;
}
int main() {
    //int n, l, u;
    int l,u;
    assert(3 == scanf("%d %d %d", &n, &l, &u));
    std::vector<int> w(n);
    for (int i = 0; i < n; i++)
        assert(1 == scanf("%d", &w[i]));
    std::vector<int> result = find_subset(l, u, w);


    printf("%d\n", (int)result.size());
    for (int i = 0; i < (int)result.size(); i++)
        printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]);
    return 0;
}

Compilation message

/tmp/cc8u50m9.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccECbh0H.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status