Submission #947135

#TimeUsernameProblemLanguageResultExecution timeMemory
947135steveonalexDetecting Molecules (IOI16_molecules)C++14
100 / 100
51 ms4952 KiB
#include <bits/stdc++.h> #include "molecules.h" using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1ULL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ll mask){return __builtin_popcountll(mask);} int ctz(ll mask){return __builtin_ctzll(mask);} int logOf(ll mask){return 63 - __builtin_clzll(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } vector<int> find_subset(int l, int r, vector<int> w) { int n = w.size(); if (r < w[0]) return vector<int>(0); vector<int> pos(n); for(int i = 0; i<n; ++i) pos[i] = i; sort(ALL(pos), [&w] (int a, int b){return w[a] < w[b];}); sort(ALL(w)); ll s = 0; for(int i: w) s += i; if (s < l) return vector<int>(0); ll delta = 0; for(int i= 0; i<n; ++i){ if (s >= l && s - delta <= r){ vector<int> ans; for(int j = i; j<n; ++j) ans.push_back(j); reverse(ALL(ans)); for(int j = 0; j < i; ++j){ if (s <= r) break; s -= w[n - j - 1] - w[j]; ans[j] = n - ans[j] - 1; } for(int &j: ans) j = pos[j]; sort(ALL(ans)); return ans; } delta += w[n - i - 1] - w[i]; s -= w[i]; } return vector<int>(0); } // int main(void){ // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // vector<int> ans = find_subset(50, 51, {11, 10, 11, 10, 11, 10, 10}); // printArr(ans); // return 0; // }
#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...