Submission #1326533

#TimeUsernameProblemLanguageResultExecution timeMemory
1326533rainerevan_Detecting Molecules (IOI16_molecules)C++20
69 / 100
32 ms4112 KiB
#include "molecules.h"
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

typedef int ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 5;
const ll LOG = 30;
#define vll vector <ll>
#define pll pair <ll, ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " " << (x) << endl;

std::vector<int> find_subset(int l, int u, std::vector<int> w) {
    vll z;
    vector <pll> v;
    ll sz = w.size();
    for(ll i = 0; i < sz; i++){
        if(w[i] >= l){
            if(w[i] <= u) return vll (1, i);
        }
        else v.push_back({w[i], i});
    }
    sort(v.begin(), v.end());
    sz = v.size();
    ll tot = 0;
    for(ll i = 0; i < sz; i++){
        tot += v[i].fi;
        if(tot >= l){
            if(tot <= u){
                for(ll j = 0; j <= i; j++) z.push_back(v[j].se);
                sort(z.begin(), z.end());
                return z;
            }
            // dari 0 sampe i-1
            tot -= v[i].fi;
            for(ll j = 0; j < i; j++){
                if(tot-v[j].fi+v[sz-1-j].fi >= l){
                    for(ll k = j+1; k < i; k++) z.push_back(v[k].se);
                    for(ll k = sz-1-j; k < sz; k++) z.push_back(v[k].se);
                    sort(z.begin(), z.end());
                    return z;
                }
                tot += -v[j].fi+v[sz-1-j].fi;
            }
            return std::vector<int>(0);
        }
    }
    return std::vector<int>(0);
}
// 10 11
// 4 4 4 5 5

Compilation message (stderr)

molecules.cpp:9:16: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
    9 | const ll INF = 1e18;
      |                ^~~~
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...