Submission #426448

# Submission time Handle Problem Language Result Execution time Memory
426448 2021-06-14T04:05:53 Z dariasc Detecting Molecules (IOI16_molecules) C++14
0 / 100
1 ms 300 KB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> return_range(vector<pair<long long, int>> prefix, int i, int j) {
    vector<int> ans(j - i + 1);
    for (int k = 0; k < ans.size(); k++) {
        ans[k] = prefix[i + k].second;
    }
    return ans;
}

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    vector<pair<long long, int>> molecules(w.size());
    for (int i = 0; i < w.size(); i++) {
        molecules[i] = {w[i], i};
    }

    sort(molecules.begin(), molecules.end());
    // make prefix sum
    for (int i = 1; i < molecules.size(); i++) {
        molecules[i].first += molecules[i-1].first;
    }

    int j = 0;
    for (int i = 0; i < molecules.size(); i++) {
        int weight = molecules[i].first;
        if (weight > u) {
            while (j < i) {
                int x = weight - molecules[j].first;
                if (l <= x && x <= u) {
                    return return_range(molecules, j+1, i);
                } else if (x < l) {
                    break;
                }

                j++;
            }
        } else if (l <= weight && weight <= u) {
            vector<int> ans = {i};
            return ans;
        }
    }

    return std::vector<int>(0);
}

Compilation message

molecules.cpp: In function 'std::vector<int> return_range(std::vector<std::pair<long long int, int> >, int, int)':
molecules.cpp:7:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |     for (int k = 0; k < ans.size(); k++) {
      |                     ~~^~~~~~~~~~~~
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i = 0; i < w.size(); i++) {
      |                     ~~^~~~~~~~~~
molecules.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i = 1; i < molecules.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~~~
molecules.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i = 0; i < molecules.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB OK (n = 1, answer = NO)
2 Correct 1 ms 204 KB OK (n = 1, answer = NO)
3 Correct 1 ms 204 KB OK (n = 1, answer = YES)
4 Incorrect 1 ms 204 KB sum of weights should be in [100..100] but it is 50
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB OK (n = 12, answer = YES)
2 Correct 1 ms 292 KB OK (n = 12, answer = YES)
3 Correct 1 ms 204 KB OK (n = 12, answer = NO)
4 Correct 1 ms 204 KB OK (n = 12, answer = NO)
5 Incorrect 1 ms 204 KB sum of weights should be in [290..300] but it is 50
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB OK (n = 1, answer = NO)
2 Correct 1 ms 204 KB OK (n = 1, answer = NO)
3 Correct 1 ms 204 KB OK (n = 1, answer = YES)
4 Incorrect 1 ms 204 KB sum of weights should be in [100..100] but it is 50
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB OK (n = 1, answer = NO)
2 Correct 1 ms 204 KB OK (n = 1, answer = NO)
3 Correct 1 ms 204 KB OK (n = 1, answer = YES)
4 Incorrect 1 ms 204 KB sum of weights should be in [100..100] but it is 50
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB OK (n = 1, answer = NO)
2 Correct 1 ms 204 KB OK (n = 1, answer = NO)
3 Correct 1 ms 204 KB OK (n = 1, answer = YES)
4 Incorrect 1 ms 204 KB sum of weights should be in [100..100] but it is 50
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB OK (n = 1, answer = NO)
2 Correct 1 ms 204 KB OK (n = 1, answer = NO)
3 Correct 1 ms 204 KB OK (n = 1, answer = YES)
4 Incorrect 1 ms 204 KB sum of weights should be in [100..100] but it is 50
5 Halted 0 ms 0 KB -