답안 #72787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72787 2018-08-27T00:20:46 Z dmfr Detecting Molecules (IOI16_molecules) C++11
0 / 100
4 ms 524 KB
#include "molecules.h"

#include <map>
#include <deque>
#include <vector>

#include <algorithm>

//#include <iostream>

using namespace std;

typedef pair<int,int> pii;

/*
4 15 17
6 8 8 7
=>2
=>2 3

4 14 15
5 5 6 6
=>0

4 10 20
15 17 16 18
=>1
=>18

*/

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    const int& N = w.size();

    std::vector<pii> wVtr(N);
    for(int i = 0; i < N; ++i)
        wVtr[i] = pii(w[i], i+1);

    std::sort(wVtr.begin(), wVtr.end());
    while(!wVtr.empty() && wVtr.front().first > u) wVtr.pop_back();
    if(wVtr.empty())                      return std::vector<int>(0);
    if(l <= wVtr.back().first && wVtr.back().first <= u) return std::vector<int>(1,wVtr.back().second);
    std::reverse(wVtr.begin(),wVtr.end());

//    cout << "w:";
//    for(const auto& i:w) cout << i << " ";
//    cout << endl;

    int UpperBound = u;
    std::vector<int> LowerBound(N);
    LowerBound[N-1] = l;
    for(int i = N-2; i >= 0; --i)
        LowerBound[i] = std::max(LowerBound[i+1] - wVtr[i+1].first, 0);

//    cout << "LowerBound:";
//    for(const auto& i:LowerBound) cout << i << " ";
//    cout << endl;

    std::map<int,std::deque<int>> PossibleNumbers;
    PossibleNumbers[0] = deque<int>();
    std::deque<std::pair<int,std::deque<int>>> ToInsert;
    for(int i = 0; i < N; ++i){
        const pii& w_i = wVtr[i];
        const int& LowerBound_i = LowerBound[i];
        for(const auto& n:PossibleNumbers)
            if(LowerBound_i <= n.first+w_i.first && n.first+w_i.first <= UpperBound){
                ToInsert.push_back(n);
                ToInsert.back().first += w_i.first;
                ToInsert.back().second.push_back(w_i.second);
            }
        while(!ToInsert.empty()){
            PossibleNumbers[ToInsert.back().first] = ToInsert.back().second;
            ToInsert.pop_back();
        }

//        cout << "PossibleNumbers (before purge):" << endl;
//        for(const auto& n:PossibleNumbers){
//            cout << n.first << ": ";
//            for(const auto& m:n.second) cout << m << " ";
//            cout << endl;
//        }

        while(!PossibleNumbers.empty() && PossibleNumbers.begin()->first < LowerBound_i)
            PossibleNumbers.erase(PossibleNumbers.begin());

//        cout << "PossibleNumbers (after purge):" << endl;
//        for(const auto& n:PossibleNumbers){
//            cout << n.first << ": ";
//            for(const auto& m:n.second) cout << m << " ";
//            cout << endl;
//        }cout << endl;

        if(PossibleNumbers.empty())
            return std::vector<int>(0);
        const auto& W = PossibleNumbers.rbegin();
        if(l <= W->first && W->first <= u)
            return std::vector<int>(W->second.begin(),W->second.end());

    }


    return std::vector<int>(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 488 KB OK (n = 1, answer = NO)
3 Incorrect 3 ms 488 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 524 KB sum of weights should be in [302..304] but it is 305
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 488 KB OK (n = 1, answer = NO)
3 Incorrect 3 ms 488 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 488 KB OK (n = 1, answer = NO)
3 Incorrect 3 ms 488 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 488 KB OK (n = 1, answer = NO)
3 Incorrect 3 ms 488 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 488 KB OK (n = 1, answer = NO)
3 Incorrect 3 ms 488 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -