Submission #921331

#TimeUsernameProblemLanguageResultExecution timeMemory
921331H1HDetecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#define T "Task"
using namespace std;


vector<int> find_subset(int l, int u, vector<int> w){
    vector<pair<int, int>> a;
    for(int i = 0; i < w.size(); ++i){
        a.push_back({w[i], i});
    }
    sort(a.begin(), a.end(), [](pair<int,int> a1, pair<int,int> a2){
        return a1.first > a2.first;
    });
    vector<int> ans;
    long long sum_val = 0;
    int id = 0;

    while(true){
        if(id == a.size())break;
        sum_val += a[id].first;
        ans.push_back(a[id].second);
        if(sum_val >= l && sum_val <= u){
            return ans;
        }
        if(sum_val > u){
            sum_val -= a[ans[0]].first;
            ans[0] = a[a.size()-1].second;
            sum_val += a[ans[0]].first;
            if(!(sum_val >= l && sum_val <= u) || id == a.size()-1){
                ans.clear();
            }
            return ans;
        }
        id += 1;
    }
    ans.clear();
    return ans;
}

void ip(){
//    vector<int> a = {15, 17, 16, 18};
//    for(auto ai : find_subset(10, 20, a)){
//        cout << ai << '\n';
//    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(T".INP", "r")){
        freopen(T".INP", "r", stdin);
        freopen(T".OUT", "w", stdout);
    }
//    int tt = 1;
////    cin >> tt;
//    while(tt--){
//        ip();
//    }
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(int i = 0; i < w.size(); ++i){
      |                    ~~^~~~~~~~~~
molecules.cpp:19:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         if(id == a.size())break;
      |            ~~~^~~~~~~~~~~
molecules.cpp:29:54: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             if(!(sum_val >= l && sum_val <= u) || id == a.size()-1){
      |                                                   ~~~^~~~~~~~~~~~~
molecules.cpp: In function 'int main()':
molecules.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(T".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
molecules.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(T".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccwv0DJx.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccUvJAJx.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status