제출 #580892

#제출 시각아이디문제언어결과실행 시간메모리
580892AriaHDetecting Molecules (IOI16_molecules)C++17
100 / 100
54 ms5668 KiB
#include "molecules.h"
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

#define F first
#define S second
#define all(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define Mp make_pair
#define endl "\n"
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 1e6 + 10;
const int LOG = 20;
const ll mod = 1e9 + 7;
const ll inf = 8e18;

int A[N], id[N];

ll ps[N];

bool cmp(int i, int j)
{
    return A[i] < A[j];
}

vector < int > find_subset(int l, int r, vector < int > w)
{
    vector < int > vec;
    int n = SZ(w);
    int base = w[0];
    for(int i = 0; i < n; i ++)
    {
        base = min(base, w[i]);
        id[i] = i;
    }
    for(int i = 0; i < n; i ++)
    {
        w[i] -= base;
        A[i] = w[i];
    }
    ///printf("base = %d\n", base);
    sort(id, id + n, cmp);
    for(int i = 0; i < n; i ++)
    {
        ///printf("i = %d id = %d\n", i, id[i]);
        ps[i] = A[id[i]];
        if(i) ps[i] += ps[i - 1];
    }
    for(int ted = 1; ted <= n; ted ++)
    {
        ll mn = 1ll * ted * base + ps[ted - 1];
        ll mx = 1ll * ted * base + ps[n - 1] - (n - ted - 1 < 0? 0 : ps[n - ted - 1]);
        //printf("ted = %d mn = %lld mx = %lld\n", ted, mn, mx);
        if(mx < l || mn > r) continue;
        ///printf("here ted = %d\n", ted);
        for(int i = ted - 1; i < n; i ++)
        {
            ll now = 1ll * ted * base + ps[i] - (i - ted < 0? 0 : ps[i - ted]);
            ///printf("i = %d now = %lld\n", i, now);
            if(l <= now && now <= r)
            {
                for(int j = i - ted + 1; j <= i; j ++)
                {
                    vec.push_back(id[j]);
                }
                return vec;
            }
        }
    }
    return vec;
}
#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...