Submission #1021899

#TimeUsernameProblemLanguageResultExecution timeMemory
1021899AmirAli_H1Detecting Molecules (IOI16_molecules)C++17
100 / 100
37 ms6860 KiB
// In the name of Allah #include <bits/stdc++.h> #include "molecules.h" using namespace std; typedef long long int ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef complex<ld> cld; #define all(x) (x).begin(),(x).end() #define len(x) ((ll) (x).size()) #define F first #define S second #define pb push_back #define sep ' ' #define endl '\n' #define Mp make_pair #define kill(x) cout << x << '\n', exit(0) #define set_dec(x) cout << fixed << setprecision(x); #define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 2e5 + 7; int n; pll a[maxn]; ll sm[maxn]; vector<int> res; int cal(int k, ll l, ll r) { for (int i = k; i <= n; i++) { ll x = sm[i] - sm[i - k]; if (x >= l && x <= r) return i - k + 1; } return -1; } vector<int> find_subset(int l, int r, vector<int> w) { n = len(w); for (int i = 1; i <= n; i++) { a[i] = Mp(w[i - 1], i - 1); } sort(a + 1, a + (n + 1)); for (int i = 1; i <= n; i++) { sm[i] = sm[i - 1] + a[i].F; } res.clear(); for (int k = 1; k <= n; k++) { ll x1 = sm[k], x2 = sm[n] - sm[n - k]; if (x1 <= r && x2 >= l) { int j = cal(k, l, r); for (int i = j; i < j + k; i++) res.pb(a[i].S); return res; } } return res; }
#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...