Submission #1198399

#TimeUsernameProblemLanguageResultExecution timeMemory
1198399andrejikusDetecting Molecules (IOI16_molecules)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
typedef long long ll;
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

const int N = 1e4 + 3;
vector<int> ww;

bool cmp(const int& i, const int& j) {
    return (ww[i] < ww[j]);
}

vector<int> find_subset(int l, int u, vector<int> w) {
    ww = w;
    vector<int> res(w.size());
    iota(res.begin(), res.end(), 0);
    sort(res.begin(), res.end(), cmp);

    int suml = 0, sumr = 0;
    for (int i = 0; i < w.size(); i++) {
        int rr = w.size()-1-i;
        suml += w[res[i]], sumr += w[res[rr]];
        if (suml <= u && sumr >= l) {
            vector<int> ans;
            int t = w.size()-1, p = 0;
            while (sumr > u && p < rr) {
                ans.push_back(res[p++]);
                sumr -= w[res[t--]];
            }
            for (int j = rr; j <= t; j++)
                ans.push_back(res[j]);

            sort(ans.begin(), ans.end());
            return ans;
        }
    }
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:40:1: warning: control reaches end of non-void function [-Wreturn-type]
   40 | }
      | ^
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...