답안 #124048

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124048 2019-07-02T12:21:02 Z Nodir_Bobiev Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
# include <iostream>
# include <vector>
# include <algorithm>

using namespace std;

vector< int > find_subset( int l, int u, vector < int > w )
{
    vector < pair < int, int > > vc;
    int n = w.size();

    for( size_t i = 0; i < n; i ++ )vc.push_back( make_pair( w[i], i) );
    sort( vc.begin(), vc.end() );

    long long sm = vc[0].first;
    vector < int > ans={ vc[0].second };

    for( int i = 1; i <n; i ++ ){
        if( sm + vc[i].first >= u ) break;
        sm += vc[i].first;
        ans.push_back( vc[i].second );
    }
    for( int i = ans.size(); i < n; i ++ ){
        if( sm >= l ) break;
        sm += vc[i].first - vc[ ans[i%ans.size()] ].first;
        ans[i%ans.size()] = vc[i].second;
    }
    if( sm < l || u < sm )
        ans.clear();
    return ans;
}

int main()
{
    vector < int > ret = find_subset( 14, 15, {5,5,6,6} );
    for( auto c: ret) {
        cout << c << ' ';
    }
    return 0;
}


Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:13:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( size_t i = 0; i < n; i ++ )vc.push_back( make_pair( w[i], i) );
                        ~~^~~
/tmp/ccsxLMSh.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc87NKI4.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status