Submission #234264

# Submission time Handle Problem Language Result Execution time Memory
234264 2020-05-23T15:28:28 Z wiwiho Detecting Molecules (IOI16_molecules) C++14
9 / 100
5 ms 384 KB
#include "molecules.h"

//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pll pair<ll, ll>
#define tiii tuple<int, int, int>
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a) / (b) + !!((a) % (b)))

//#define TEST

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
using namespace __gnu_pbds;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

vector<ll> BIT;

int lowbit(int x){
    return x & -x;
}

void modify(int x, ll v){
    for(; x < BIT.size(); x += lowbit(x)){
        BIT[x] += v;
    }
}

vector<int> find_subset(int L, int U, vector<int> w) {

    int n = w.size();
    vector<pii> t(n);
    BIT.resize(n + 1);
    for(int i = 0; i < n; i++){
        t[i] = mp(w[i], i);
    }

    lsort(t);
    for(int i = 0; i < n; i++){
        modify(i + 1, t[i].F);
    }

    int tmp = 0;
    ll sum = 0;
    for(int i = __lg(n); i >= 0; i--){
        if(tmp + (1 << i) > n) continue;
        if(sum + BIT[tmp + (1 << i)] < L){
            tmp += (1 << i);
            sum += BIT[tmp];
        }
    }

    if(tmp < n && sum + t[tmp].F >= L && sum + t[tmp].F <= U){
        vector<int> ans;
        for(int i = 0; i <= tmp; i++) ans.eb(t[i].S);
        return ans;
    }

    vector<int> pos(n);
    for(int i = 0; i < n; i++) pos[i] = i;
    for(int i = 0; i < n / 2; i++){
        modify(i + 1, -t[i].F);
        modify(i + 1, t[n - i - 1].F);
        pos[i] = n - i - 1;

        int k = n - i - 1;

        tmp = 0;
        sum = 0;

        for(int j = __lg(k); j >= 0; j--){
            if(tmp + (1 << j) > n) continue;
            if(sum + BIT[tmp + (1 << j)] < L){
                tmp += (1 << j);
                sum += BIT[tmp];
            }
        }
//        cerr << i << " " << tmp << "\n";

        if(tmp < k && sum + t[tmp].F >= L && sum + t[tmp].F <= U){
            vector<int> ans;
            for(int j = 0; j <= tmp; j++) ans.eb(t[pos[j]].S);
            return ans;
        }

    }

    return vector<int>();
}


Compilation message

molecules.cpp: In function 'void modify(int, ll)':
molecules.cpp:57:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(; x < BIT.size(); x += lowbit(x)){
           ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 256 KB OK (n = 1, answer = NO)
3 Correct 4 ms 256 KB OK (n = 1, answer = YES)
4 Correct 5 ms 384 KB OK (n = 2, answer = YES)
5 Correct 5 ms 384 KB OK (n = 2, answer = YES)
6 Correct 5 ms 384 KB OK (n = 3, answer = YES)
7 Correct 5 ms 384 KB OK (n = 3, answer = YES)
8 Correct 4 ms 256 KB OK (n = 3, answer = YES)
9 Correct 5 ms 256 KB OK (n = 3, answer = YES)
10 Correct 5 ms 256 KB OK (n = 3, answer = YES)
11 Correct 5 ms 384 KB OK (n = 3, answer = YES)
12 Correct 4 ms 256 KB OK (n = 3, answer = YES)
13 Correct 5 ms 384 KB OK (n = 3, answer = NO)
14 Correct 4 ms 256 KB OK (n = 3, answer = YES)
15 Correct 5 ms 256 KB OK (n = 3, answer = YES)
16 Correct 4 ms 256 KB OK (n = 3, answer = NO)
17 Correct 5 ms 256 KB OK (n = 3, answer = NO)
18 Correct 5 ms 384 KB OK (n = 100, answer = NO)
19 Correct 5 ms 256 KB OK (n = 100, answer = YES)
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 12, answer = YES)
2 Correct 4 ms 256 KB OK (n = 12, answer = YES)
3 Correct 4 ms 384 KB OK (n = 12, answer = NO)
4 Correct 5 ms 384 KB OK (n = 12, answer = NO)
5 Correct 5 ms 256 KB OK (n = 12, answer = YES)
6 Incorrect 4 ms 256 KB Contestant can not find answer, jury can
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 256 KB OK (n = 1, answer = NO)
3 Correct 4 ms 256 KB OK (n = 1, answer = YES)
4 Correct 5 ms 384 KB OK (n = 2, answer = YES)
5 Correct 5 ms 384 KB OK (n = 2, answer = YES)
6 Correct 5 ms 384 KB OK (n = 3, answer = YES)
7 Correct 5 ms 384 KB OK (n = 3, answer = YES)
8 Correct 4 ms 256 KB OK (n = 3, answer = YES)
9 Correct 5 ms 256 KB OK (n = 3, answer = YES)
10 Correct 5 ms 256 KB OK (n = 3, answer = YES)
11 Correct 5 ms 384 KB OK (n = 3, answer = YES)
12 Correct 4 ms 256 KB OK (n = 3, answer = YES)
13 Correct 5 ms 384 KB OK (n = 3, answer = NO)
14 Correct 4 ms 256 KB OK (n = 3, answer = YES)
15 Correct 5 ms 256 KB OK (n = 3, answer = YES)
16 Correct 4 ms 256 KB OK (n = 3, answer = NO)
17 Correct 5 ms 256 KB OK (n = 3, answer = NO)
18 Correct 5 ms 384 KB OK (n = 100, answer = NO)
19 Correct 5 ms 256 KB OK (n = 100, answer = YES)
20 Correct 5 ms 256 KB OK (n = 12, answer = YES)
21 Correct 4 ms 256 KB OK (n = 12, answer = YES)
22 Correct 4 ms 384 KB OK (n = 12, answer = NO)
23 Correct 5 ms 384 KB OK (n = 12, answer = NO)
24 Correct 5 ms 256 KB OK (n = 12, answer = YES)
25 Incorrect 4 ms 256 KB Contestant can not find answer, jury can
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 256 KB OK (n = 1, answer = NO)
3 Correct 4 ms 256 KB OK (n = 1, answer = YES)
4 Correct 5 ms 384 KB OK (n = 2, answer = YES)
5 Correct 5 ms 384 KB OK (n = 2, answer = YES)
6 Correct 5 ms 384 KB OK (n = 3, answer = YES)
7 Correct 5 ms 384 KB OK (n = 3, answer = YES)
8 Correct 4 ms 256 KB OK (n = 3, answer = YES)
9 Correct 5 ms 256 KB OK (n = 3, answer = YES)
10 Correct 5 ms 256 KB OK (n = 3, answer = YES)
11 Correct 5 ms 384 KB OK (n = 3, answer = YES)
12 Correct 4 ms 256 KB OK (n = 3, answer = YES)
13 Correct 5 ms 384 KB OK (n = 3, answer = NO)
14 Correct 4 ms 256 KB OK (n = 3, answer = YES)
15 Correct 5 ms 256 KB OK (n = 3, answer = YES)
16 Correct 4 ms 256 KB OK (n = 3, answer = NO)
17 Correct 5 ms 256 KB OK (n = 3, answer = NO)
18 Correct 5 ms 384 KB OK (n = 100, answer = NO)
19 Correct 5 ms 256 KB OK (n = 100, answer = YES)
20 Correct 5 ms 256 KB OK (n = 12, answer = YES)
21 Correct 4 ms 256 KB OK (n = 12, answer = YES)
22 Correct 4 ms 384 KB OK (n = 12, answer = NO)
23 Correct 5 ms 384 KB OK (n = 12, answer = NO)
24 Correct 5 ms 256 KB OK (n = 12, answer = YES)
25 Incorrect 4 ms 256 KB Contestant can not find answer, jury can
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 256 KB OK (n = 1, answer = NO)
3 Correct 4 ms 256 KB OK (n = 1, answer = YES)
4 Correct 5 ms 384 KB OK (n = 2, answer = YES)
5 Correct 5 ms 384 KB OK (n = 2, answer = YES)
6 Correct 5 ms 384 KB OK (n = 3, answer = YES)
7 Correct 5 ms 384 KB OK (n = 3, answer = YES)
8 Correct 4 ms 256 KB OK (n = 3, answer = YES)
9 Correct 5 ms 256 KB OK (n = 3, answer = YES)
10 Correct 5 ms 256 KB OK (n = 3, answer = YES)
11 Correct 5 ms 384 KB OK (n = 3, answer = YES)
12 Correct 4 ms 256 KB OK (n = 3, answer = YES)
13 Correct 5 ms 384 KB OK (n = 3, answer = NO)
14 Correct 4 ms 256 KB OK (n = 3, answer = YES)
15 Correct 5 ms 256 KB OK (n = 3, answer = YES)
16 Correct 4 ms 256 KB OK (n = 3, answer = NO)
17 Correct 5 ms 256 KB OK (n = 3, answer = NO)
18 Correct 5 ms 384 KB OK (n = 100, answer = NO)
19 Correct 5 ms 256 KB OK (n = 100, answer = YES)
20 Correct 5 ms 256 KB OK (n = 12, answer = YES)
21 Correct 4 ms 256 KB OK (n = 12, answer = YES)
22 Correct 4 ms 384 KB OK (n = 12, answer = NO)
23 Correct 5 ms 384 KB OK (n = 12, answer = NO)
24 Correct 5 ms 256 KB OK (n = 12, answer = YES)
25 Incorrect 4 ms 256 KB Contestant can not find answer, jury can
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 4 ms 256 KB OK (n = 1, answer = NO)
3 Correct 4 ms 256 KB OK (n = 1, answer = YES)
4 Correct 5 ms 384 KB OK (n = 2, answer = YES)
5 Correct 5 ms 384 KB OK (n = 2, answer = YES)
6 Correct 5 ms 384 KB OK (n = 3, answer = YES)
7 Correct 5 ms 384 KB OK (n = 3, answer = YES)
8 Correct 4 ms 256 KB OK (n = 3, answer = YES)
9 Correct 5 ms 256 KB OK (n = 3, answer = YES)
10 Correct 5 ms 256 KB OK (n = 3, answer = YES)
11 Correct 5 ms 384 KB OK (n = 3, answer = YES)
12 Correct 4 ms 256 KB OK (n = 3, answer = YES)
13 Correct 5 ms 384 KB OK (n = 3, answer = NO)
14 Correct 4 ms 256 KB OK (n = 3, answer = YES)
15 Correct 5 ms 256 KB OK (n = 3, answer = YES)
16 Correct 4 ms 256 KB OK (n = 3, answer = NO)
17 Correct 5 ms 256 KB OK (n = 3, answer = NO)
18 Correct 5 ms 384 KB OK (n = 100, answer = NO)
19 Correct 5 ms 256 KB OK (n = 100, answer = YES)
20 Correct 5 ms 256 KB OK (n = 12, answer = YES)
21 Correct 4 ms 256 KB OK (n = 12, answer = YES)
22 Correct 4 ms 384 KB OK (n = 12, answer = NO)
23 Correct 5 ms 384 KB OK (n = 12, answer = NO)
24 Correct 5 ms 256 KB OK (n = 12, answer = YES)
25 Incorrect 4 ms 256 KB Contestant can not find answer, jury can
26 Halted 0 ms 0 KB -