Submission #281882

# Submission time Handle Problem Language Result Execution time Memory
281882 2020-08-23T15:16:00 Z A02 Detecting Molecules (IOI16_molecules) C++14
0 / 100
1 ms 384 KB
#include "molecules.h"
#include <vector>
#include <iostream>
#include <set>
#include <algorithm>
#include <utility>

using namespace std;

std::vector<int> find_subset(int l, int u, std::vector<int> w) {

    vector<pair<int, int> > w2;

    for (int i = 0; i < w.size(); i++){
        w2.push_back(make_pair(w[i], i));
    }

    sort(w2.begin(), w2.end());

    long long total = 0;
    set<int> result;

    int i = 0;

    for (; (i < w2.size()) && (total + w2[i].first <= u); i++){
        total += w2[i].first;
        result.insert(w2[i].second);
    }


    int result_size = i;

    long long max_total = 0;

    for (int j = w2.size() - 1; j >= w2.size() - result_size; j--){
        max_total += w2[j].first;
    }

    if (max_total < l){
        return vector<int> ();
    }

    int current_lower_max = i - 1;

    while (total < l){

        result.erase(w2[current_lower_max].second);
        result.insert(w2[w2.size() - 1 - (i - 1 - current_lower_max)].second);
        total += w2[w.size() - 1 - (i - current_lower_max)].first;
        total -= w2[current_lower_max].first;

        current_lower_max--;
    }

    vector<int> r;
    for (set<int>::iterator it = result.begin(); it != result.end(); it++){
        r.push_back(*(it));
    }

    return r;
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (int i = 0; i < w.size(); i++){
      |                     ~~^~~~~~~~~~
molecules.cpp:25: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]
   25 |     for (; (i < w2.size()) && (total + w2[i].first <= u); i++){
      |             ~~^~~~~~~~~~~
molecules.cpp:35:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int j = w2.size() - 1; j >= w2.size() - result_size; j--){
      |                                 ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB OK (n = 12, answer = YES)
2 Correct 1 ms 256 KB OK (n = 12, answer = YES)
3 Correct 0 ms 256 KB OK (n = 12, answer = NO)
4 Correct 0 ms 256 KB OK (n = 12, answer = NO)
5 Correct 1 ms 256 KB OK (n = 12, answer = YES)
6 Incorrect 0 ms 256 KB sum of weights should be in [306..310] but it is 404
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -