Submission #1226739

#TimeUsernameProblemLanguageResultExecution timeMemory
1226739JerDetecting Molecules (IOI16_molecules)C++20
19 / 100
1 ms328 KiB
#include "molecules.h"
#include <bits/stdc++.h>

using namespace std;

std::vector<int> find_subset(int l, int u, std::vector<int> w)
{
    int a = INT_MAX, b = 0;
    int c1 = 0, c2 = 0;

    for (auto i : w)
        a = min(a, i), b = max(b, i);

    if (a == b)
        b = -1;

    for (auto i : w)
        c1 += (i == a), c2 += (i == b);

    int o1 = c1, o2 = c2, sum = 0;

    while (sum + a <= u and c1 > 0)
        sum += a, c1--;

    while (sum + b <= u and c2 > 0)
        sum += b, c2--;

    while (sum < l and c2 > 0)
        sum++, c2--, c1++;

    if (sum < l or sum > u)
        return {};

    vector<int> res;
    for (int i = 0; i < w.size(); i++)
    {
        if (o1 > c1 and w[i] == a)
            res.push_back(i), o1--;
        if (o2 > c2 and w[i] == b)
            res.push_back(i), o2--;
    }

    return res;
}

Compilation message (stderr)

molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...