답안 #321815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321815 2020-11-13T12:06:11 Z nikatamliani Detecting Molecules (IOI16_molecules) C++14
0 / 100
1 ms 492 KB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> find_subset(int l, int u, vector<int>w) {
	int n = w.size();
    vector<int> indices(n);
    for(int i = 0; i < n; ++i) {
        indices[i] = i; 
    }
    sort(indices.begin(), indices.end(), [&](int x, int y) {
        return w[x] > w[y];
    });
    #define ll long long
    vector<int> result;
    ll sum = 0, cnt = 0, save = 0;
    for(int i = 0; i < n; ++i) {
        int index = indices[i]; 
        sum += w[index];
        result.push_back(index);
        ++cnt;
        if(sum >= l) {
            save = i + 1;
            break;
        }
    }
    int ptr = 0; 
    while(save < n && sum > u && ptr < result.size()) {
        sum -= result[ptr];
        result[ptr] = indices[save++];
        sum += result[ptr++];
    }
    if(sum <= u) {
        assert(sum >= l);
    } else {
    	result.clear();
	}
    return result;
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:27:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     while(save < n && sum > u && ptr < result.size()) {
      |                                  ~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -