Submission #170993

#TimeUsernameProblemLanguageResultExecution timeMemory
170993bloopieIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
299 ms20880 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 41; unordered_map<ll,ll> memo[MAXN]; unordered_map<ll,ll> memo2[MAXN]; int n; ll mm; ll a[MAXN]; ll b[MAXN]; int n1,n2; vector<ll> p1,p2; void solve1(int i,ll m) { if(m > mm) return; if(i == n1) { p1.push_back(m); return; } solve1(i + 1 , m); solve1(i + 1 , m + a[i]); } void solve2(int i,ll m) { if(m > mm) return ; if(i == n2) { p2.push_back(m); return; } solve2(i + 1 , m); solve2(i + 1 , m + b[i]); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> mm; n1 = n / 2; n2 = n - n / 2; for(int i = 0 ; i < n1 ; i++) cin >> a[i]; for(int i = 0 ; i < n2 ; i++) cin >> b[i]; solve1(0,0); solve2(0,0); sort(p1.begin(),p1.end()); sort(p2.begin(),p2.end()); ll ans = 0; if(p1.size() < p2.size()) swap(p1,p2); for(int i = 0 ; i < p1.size() ; i++) { //++ans; auto idx = upper_bound(p2.begin(),p2.end(),mm - p1[i]) - p2.begin(); ans+=idx; } cout << ans ; }

Compilation message (stderr)

bobek.cpp: In function 'int main()':
bobek.cpp:60:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0 ; i < p1.size() ; i++)
                     ~~^~~~~~~~~~~
#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...