Submission #321822

# Submission time Handle Problem Language Result Execution time Memory
321822 2020-11-13T12:11:25 Z nikatamliani Detecting Molecules (IOI16_molecules) C++14
0 / 100
1000 ms 364 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, save = 0;
    for(int i = 0; i < n; ++i) {
        int index = indices[i]; 
        sum += w[index];
        result.push_back(index);
        if(sum >= l) {
            save = i + 1;
            break;
        }
    }
    int ptr = 0; 
    while(save < n && sum > u && ptr < result.size()) {
        sum -= w[result[ptr]];
        result[ptr] = indices[save++];
        sum += w[result[ptr++]];
    }
    if(sum <= u) {
    	if(sum < l)while(true) {}
        assert(sum >= l);
        return result;
    } 
    return vector<int>{};
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:26:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     while(save < n && sum > u && ptr < result.size()) {
      |                                  ~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB OK (n = 12, answer = YES)
2 Correct 0 ms 364 KB OK (n = 12, answer = YES)
3 Correct 0 ms 364 KB OK (n = 12, answer = NO)
4 Correct 1 ms 364 KB OK (n = 12, answer = NO)
5 Correct 1 ms 364 KB OK (n = 12, answer = YES)
6 Correct 1 ms 364 KB OK (n = 12, answer = YES)
7 Correct 1 ms 364 KB OK (n = 12, answer = YES)
8 Correct 0 ms 364 KB OK (n = 12, answer = YES)
9 Correct 1 ms 364 KB OK (n = 6, answer = YES)
10 Correct 1 ms 364 KB OK (n = 12, answer = YES)
11 Execution timed out 1096 ms 364 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -