Submission #425805

#TimeUsernameProblemLanguageResultExecution timeMemory
425805InternetPerson10Detecting Molecules (IOI16_molecules)C++17
69 / 100
51 ms6504 KiB
#include "molecules.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

vector<pair<int, int>> ps;
vector<int> ans, s, p, b;

vector<int> find_subset(int l, int u, std::vector<int> w) {
    ll x = 0, g = -1;
    ps.resize(w.size());
    for(int i = 0; i < w.size(); i++)  {
        ps[i] = {w[i], i};
    }
    sort(ps.begin(), ps.end());
    for(int i = 0; i < w.size(); i++) {
        w[i] = ps[i].first;
    }
    s.resize(w.size());
    p.resize(w.size());
    for(int i = 0; i < w.size(); i++) {
        if(i == 0) s[i] = w[i];
        else s[i] = s[i-1] + w[i];
    }
    for(int i = w.size() - 1; i >= 0; i--) {
        if(i == w.size() - 1) p[w.size() - 1 - i] = w[i];
        else p[w.size() - 1 - i] = p[w.size() - 2 - i] + w[i];
    }
    for(int i = 0; i < w.size(); i++) {
        if(max(l, s[i]) <= min(u, p[i])) {
            ans.resize(i+1);
            for(int j = 0; j <= i; j++) ans[j] = j;
            for(int j = 0; j <= i; j++) x += w[j];
            g = i;
            while(x < l) {
                x -= w[ans[g]];
                ans[g] = (g - i) + w.size() - 1;
                x += w[ans[g]];
                g--;
            }
            for(int j = 0; j <= i; j++) ans[j] = ps[ans[j]].second;
            return ans;
        }
    }
    return vector<int>(0);
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i = 0; i < w.size(); i++)  {
      |                    ~~^~~~~~~~~~
molecules.cpp:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i = 0; i < w.size(); i++) {
      |                    ~~^~~~~~~~~~
molecules.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i = 0; i < w.size(); i++) {
      |                    ~~^~~~~~~~~~
molecules.cpp:28:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         if(i == w.size() - 1) p[w.size() - 1 - i] = w[i];
      |            ~~^~~~~~~~~~~~~~~
molecules.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i = 0; i < w.size(); i++) {
      |                    ~~^~~~~~~~~~
#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...