Submission #39419

#TimeUsernameProblemLanguageResultExecution timeMemory
39419farmersriceIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
256 ms26792 KiB
#include <bits/stdc++.h> //#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") //#pragma GCC target ("avx,tune=native") //Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside. AVX is better slightly /* TASK: hidden LANG: C++11 */ using namespace std; typedef long long ll; typedef pair<int, int> pair2; typedef pair<int, pair<int, int> > pair3; typedef pair<int, pair<int, pair<int, int> > > pair4; #define MAXN 43 #define INF 1000000000000000000LL #define mp make_pair #define add push_back #define remove pop int n; ll values[MAXN]; int size1, size2; ll m; vector<ll> one; vector<ll> two; void dfs(int depth, ll sum, int bound, vector<ll> &target) { if (depth == bound) { target.add(sum); return; } dfs(depth + 1, sum + values[depth], bound, target); dfs(depth + 1, sum, bound, target); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> values[i]; } dfs(0, 0, n / 2, one); dfs(n / 2, 0, n, two); sort(one.begin(), one.end()); sort(two.begin(), two.end()); //assert(one.size() + two.size() < 5000000); ll answer = 0; int twopointer = two.size() - 1; for (int i = 0; i < (int) (one.size()); i++) { if (one[i] > m) break; while (twopointer >= 0 && two[twopointer] > m - one[i]) { twopointer--; } answer += twopointer + 1; } cout << answer << endl; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...