Submission #928950

#TimeUsernameProblemLanguageResultExecution timeMemory
928950FoolestboyDetecting Molecules (IOI16_molecules)C++14
100 / 100
42 ms7276 KiB
#ifndef GNORT #include "molecules.h" #endif #include <bits/stdc++.h> #define SQR(x) (1LL * ((x) * (x))) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(s) (int)s.size() #define prev __prev #define next __next #define left __left #define right __right #define mp make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vll vector<ll> typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef unsigned int ui; using namespace std; const int mod = 1e9 + 7; const int INF = 1e9 + 7; const ll INFLL = (ll)2e18 + 7LL; const ld PI = acos(-1); const int dx[] = {1, -1, 0, 0, -1, 1, 1, -1}; const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1}; template<class BUI, class TRONG> bool minimize(BUI &x, const TRONG y){ if(x > y){ x = y; return true; } else return false; } template<class BUI, class TRONG> bool maximize(BUI &x, const TRONG y){ if(x < y){ x = y; return true; } else return false; } /* Author : Bui Nguyen Duc Trong, Luong Van Chanh High School for the gifted*/ /* Template is copied by Trong */ /** Losing in Provincial Contests **/ /** TRYING HARDER**/ /** ORZ **/ /* -----------------[ MAIN CODE GOES HERE ]----------------- */ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<int> find_subset(int l, int u, vector<int> w){ vector<int> ans; int n = sz(w); vector<pair<ll, int>> val(n); for(int i = 0; i < n; i++) val[i] = mp(w[i], i); sort(all(val)); for(int i = 1; i < n; i++) val[i].fi += val[i - 1].fi; auto getRange = [&](int l, int r) -> ll{ if(l == 0) return val[r].fi; return val[r].fi - val[l - 1].fi; }; for(int i = 0; i < n; i++){ int lo = 0, hi = i, p = -1; while(lo <= hi){ int mid = (lo + hi) >> 1; if(getRange(mid, i) >= l){ p = mid; lo = mid + 1; } else hi = mid - 1; } if(p != -1 && getRange(p, i) <= u){ for(int j = p; j <= i; j++) ans.push_back(val[j].se); break; } } return ans; } /* 4 15 17 6 8 8 7 */ #ifdef GNORT void solve(){ int n, l, u; cin >> n >> l >> u; vector<int> w(n); for(int i = 0; i < n; i++) cin >> w[i]; vector<int> ans = find_subset(l, u, w); cout << sz(ans) << ": "; for(int x : ans) cout << x << ' '; cout << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); const bool multitest = 0; int tt = 1; if(multitest) cin >> tt; while( tt-- ){ solve(); } return 0; } #endif
#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...