제출 #417622

#제출 시각아이디문제언어결과실행 시간메모리
417622TricksterDetecting Molecules (IOI16_molecules)C++14
9 / 100
1 ms204 KiB
//Suleyman Atayew

#include "molecules.h"
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <bitset>
#include <queue>
#include <cmath>
#include <map>
#include <set>
 
#define N 200010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define mod 1000000007
#define pii pair <ll, ll>
#define sz(a) (ll)(a.size())
ll bigmod(ll a, ll b) { if(b==0)return 1; ll ret = bigmod(a, b/2); return ret * ret % mod * (b%2 ? a : 1) % mod; }

using namespace std;

ll n;
ll v[N];
ll p[N][5];
pii arr[N];

vector <int> find_subset(int l, int u, vector <int> w)
{
    n = sz(w);

    for(ll i = 1; i <= n; i++) arr[i] = {w[i-1], i-1};

    sort(arr + 1, arr+n+1);
    sort(w.begin(), w.end());
    for(ll i = 1; i <= n; i++) v[i] = w[i-1], p[i][0] = p[i-1][0] + v[i];
    for(ll i = n; i >= 1; i--) p[i][1] = p[i+1][1] + v[i];

    for(ll i = 1; i <= n; i++) {
        vector <int> ret;

        if(p[i][0] >= l && p[i][0] <= u) {
            for(ll h = 1; h <= i; h++) ret.pb(arr[h].ss);

            return ret;
        }
        if(p[n-i+1][1] >= l && p[n-i+1][1] <= u) {
            for(ll h = 1; h <= i; h++) ret.pb(arr[n-h+1].ss);

            return ret;
        }

        if(p[i][0] <= l && p[n-i+1][1] >= u) {
            ll sum = p[i][0];
            for(ll h = i, j = n; h >= 1 && j >= n-i+1; h--, j--) {
                if(sum >= l && sum <= u) {
                    for(ll x = i; x >= 1; x--) ret.pb(arr[x].ss);

                    return ret;
                }

                if(sum + v[j] - v[i] <= u) {
                    sum += v[j] - v[i];
                    ret.pb(arr[j].ss);
                }
            }

            if(sum >= l && sum <= u) {
                return ret;
            }
        }
    }

    vector <int> ret;
    return ret;
}
#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...