Submission #209098

# Submission time Handle Problem Language Result Execution time Memory
209098 2020-03-13T07:42:21 Z my99n Detecting Molecules (IOI16_molecules) C++14
9 / 100
5 ms 376 KB
#include<bits/stdc++.h>
using namespace std;
#include "molecules.h"

vector<int> find_subset(int l, int u, vector<int> w) {
    vector<int> ans;
    vector<pair<int,int>> s;
    for (int i = 0; i < w.size(); i++) s.push_back({w[i], i});
    sort(s.begin(), s.end());
    int wmax = (s.end()-1)->first, wmin = s.begin()->first;
    if (wmin > u) return vector<int>(0);
    if (l <= wmin and u >= wmin) return vector<int>(1, s[0].second);
    if (l <= wmax and u >= wmax) return vector<int>(1, s.back().second);
    reverse(s.begin(), s.end());

    int val = 0;
    for (int i = 0; i < s.size(); i++) {
        ans.push_back(s.size()-s[i].second-1);
        val += s[i].first;
        if (val < l) continue;
        if (l <= val and val <= u) return ans;
        if (u < val) { 
            ans.pop_back();
            val -= w[i];
            continue;
        }
    }

    return vector<int>(0);
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:8:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < w.size(); i++) s.push_back({w[i], i});
                     ~~^~~~~~~~~~
molecules.cpp:17:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); i++) {
                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB OK (n = 1, answer = NO)
2 Correct 5 ms 376 KB OK (n = 1, answer = NO)
3 Correct 5 ms 256 KB OK (n = 1, answer = YES)
4 Correct 4 ms 256 KB OK (n = 2, answer = YES)
5 Correct 4 ms 256 KB OK (n = 2, answer = YES)
6 Correct 5 ms 256 KB OK (n = 3, answer = YES)
7 Correct 5 ms 256 KB OK (n = 3, answer = YES)
8 Correct 4 ms 256 KB OK (n = 3, answer = YES)
9 Correct 4 ms 256 KB OK (n = 3, answer = YES)
10 Correct 5 ms 256 KB OK (n = 3, answer = YES)
11 Correct 5 ms 376 KB OK (n = 3, answer = YES)
12 Correct 5 ms 256 KB OK (n = 3, answer = YES)
13 Correct 4 ms 256 KB OK (n = 3, answer = NO)
14 Correct 5 ms 256 KB OK (n = 3, answer = YES)
15 Correct 5 ms 256 KB OK (n = 3, answer = YES)
16 Correct 5 ms 256 KB OK (n = 3, answer = NO)
17 Correct 5 ms 376 KB OK (n = 3, answer = NO)
18 Correct 5 ms 256 KB OK (n = 100, answer = NO)
19 Correct 5 ms 376 KB OK (n = 100, answer = YES)
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 256 KB sum of weights should be in [302..304] but it is 301
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB OK (n = 1, answer = NO)
2 Correct 5 ms 376 KB OK (n = 1, answer = NO)
3 Correct 5 ms 256 KB OK (n = 1, answer = YES)
4 Correct 4 ms 256 KB OK (n = 2, answer = YES)
5 Correct 4 ms 256 KB OK (n = 2, answer = YES)
6 Correct 5 ms 256 KB OK (n = 3, answer = YES)
7 Correct 5 ms 256 KB OK (n = 3, answer = YES)
8 Correct 4 ms 256 KB OK (n = 3, answer = YES)
9 Correct 4 ms 256 KB OK (n = 3, answer = YES)
10 Correct 5 ms 256 KB OK (n = 3, answer = YES)
11 Correct 5 ms 376 KB OK (n = 3, answer = YES)
12 Correct 5 ms 256 KB OK (n = 3, answer = YES)
13 Correct 4 ms 256 KB OK (n = 3, answer = NO)
14 Correct 5 ms 256 KB OK (n = 3, answer = YES)
15 Correct 5 ms 256 KB OK (n = 3, answer = YES)
16 Correct 5 ms 256 KB OK (n = 3, answer = NO)
17 Correct 5 ms 376 KB OK (n = 3, answer = NO)
18 Correct 5 ms 256 KB OK (n = 100, answer = NO)
19 Correct 5 ms 376 KB OK (n = 100, answer = YES)
20 Incorrect 5 ms 256 KB sum of weights should be in [302..304] but it is 301
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB OK (n = 1, answer = NO)
2 Correct 5 ms 376 KB OK (n = 1, answer = NO)
3 Correct 5 ms 256 KB OK (n = 1, answer = YES)
4 Correct 4 ms 256 KB OK (n = 2, answer = YES)
5 Correct 4 ms 256 KB OK (n = 2, answer = YES)
6 Correct 5 ms 256 KB OK (n = 3, answer = YES)
7 Correct 5 ms 256 KB OK (n = 3, answer = YES)
8 Correct 4 ms 256 KB OK (n = 3, answer = YES)
9 Correct 4 ms 256 KB OK (n = 3, answer = YES)
10 Correct 5 ms 256 KB OK (n = 3, answer = YES)
11 Correct 5 ms 376 KB OK (n = 3, answer = YES)
12 Correct 5 ms 256 KB OK (n = 3, answer = YES)
13 Correct 4 ms 256 KB OK (n = 3, answer = NO)
14 Correct 5 ms 256 KB OK (n = 3, answer = YES)
15 Correct 5 ms 256 KB OK (n = 3, answer = YES)
16 Correct 5 ms 256 KB OK (n = 3, answer = NO)
17 Correct 5 ms 376 KB OK (n = 3, answer = NO)
18 Correct 5 ms 256 KB OK (n = 100, answer = NO)
19 Correct 5 ms 376 KB OK (n = 100, answer = YES)
20 Incorrect 5 ms 256 KB sum of weights should be in [302..304] but it is 301
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB OK (n = 1, answer = NO)
2 Correct 5 ms 376 KB OK (n = 1, answer = NO)
3 Correct 5 ms 256 KB OK (n = 1, answer = YES)
4 Correct 4 ms 256 KB OK (n = 2, answer = YES)
5 Correct 4 ms 256 KB OK (n = 2, answer = YES)
6 Correct 5 ms 256 KB OK (n = 3, answer = YES)
7 Correct 5 ms 256 KB OK (n = 3, answer = YES)
8 Correct 4 ms 256 KB OK (n = 3, answer = YES)
9 Correct 4 ms 256 KB OK (n = 3, answer = YES)
10 Correct 5 ms 256 KB OK (n = 3, answer = YES)
11 Correct 5 ms 376 KB OK (n = 3, answer = YES)
12 Correct 5 ms 256 KB OK (n = 3, answer = YES)
13 Correct 4 ms 256 KB OK (n = 3, answer = NO)
14 Correct 5 ms 256 KB OK (n = 3, answer = YES)
15 Correct 5 ms 256 KB OK (n = 3, answer = YES)
16 Correct 5 ms 256 KB OK (n = 3, answer = NO)
17 Correct 5 ms 376 KB OK (n = 3, answer = NO)
18 Correct 5 ms 256 KB OK (n = 100, answer = NO)
19 Correct 5 ms 376 KB OK (n = 100, answer = YES)
20 Incorrect 5 ms 256 KB sum of weights should be in [302..304] but it is 301
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB OK (n = 1, answer = NO)
2 Correct 5 ms 376 KB OK (n = 1, answer = NO)
3 Correct 5 ms 256 KB OK (n = 1, answer = YES)
4 Correct 4 ms 256 KB OK (n = 2, answer = YES)
5 Correct 4 ms 256 KB OK (n = 2, answer = YES)
6 Correct 5 ms 256 KB OK (n = 3, answer = YES)
7 Correct 5 ms 256 KB OK (n = 3, answer = YES)
8 Correct 4 ms 256 KB OK (n = 3, answer = YES)
9 Correct 4 ms 256 KB OK (n = 3, answer = YES)
10 Correct 5 ms 256 KB OK (n = 3, answer = YES)
11 Correct 5 ms 376 KB OK (n = 3, answer = YES)
12 Correct 5 ms 256 KB OK (n = 3, answer = YES)
13 Correct 4 ms 256 KB OK (n = 3, answer = NO)
14 Correct 5 ms 256 KB OK (n = 3, answer = YES)
15 Correct 5 ms 256 KB OK (n = 3, answer = YES)
16 Correct 5 ms 256 KB OK (n = 3, answer = NO)
17 Correct 5 ms 376 KB OK (n = 3, answer = NO)
18 Correct 5 ms 256 KB OK (n = 100, answer = NO)
19 Correct 5 ms 376 KB OK (n = 100, answer = YES)
20 Incorrect 5 ms 256 KB sum of weights should be in [302..304] but it is 301
21 Halted 0 ms 0 KB -