답안 #281867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
281867 2020-08-23T15:02:29 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) {

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

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

    int i = 0;

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


    int result_size = i;

    long long max_total = 0;

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

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

    int current_lower_max = i - 1;

    while (total < l){

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

        current_lower_max--;
    }

    vector<int> r;
    for (multiset<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:19:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (; i < w.size() && total + w[i] <= u; i++){
      |            ~~^~~~~~~~~~
molecules.cpp:29:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int j = w.size() - 1; j >= w.size() - result_size; j--){
      |                                ~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB OK (n = 12, answer = YES)
2 Correct 1 ms 384 KB OK (n = 12, answer = YES)
3 Correct 1 ms 256 KB OK (n = 12, answer = NO)
4 Correct 1 ms 384 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 305
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -