Submission #170977

#TimeUsernameProblemLanguageResultExecution timeMemory
170977redaIce Hockey World Championship (CEOI15_bobek)C++14
100 / 100
579 ms21060 KiB
#include<bits/stdc++.h> #define endl '\n' #define pii pair<int,int> #define fi first #define se second #define ll long long #define pb push_back #define all(x) x.begin(),x.end() #pragma GCC optimize ("Ofast","unroll-loops") using namespace std; const int MOD = 1e9+7; const int MAXN = 50; ll ans = 0 ; ll n, m ; void solve(ll idx , ll sum , vector<ll> arr , vector<ll> &v ) { if(idx==arr.size() ) { if(sum<=m)v.push_back(sum); return ; } solve(idx+1,sum,arr,v); solve(idx+1,sum+arr[idx],arr,v); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m ; vector<ll> a , b ; for(ll i=1;i<=n;i++) { ll x; cin >> x ; if(i%2==0) { a.push_back(x); } else { b.push_back(x); } } vector<ll> v1,v2; solve(0,0,a,v1); solve(0,0,b,v2); sort(all(v1)); sort(all(v2)); for(auto it : v1) { ll l = 0 ; ll r= v2.size()-1; ll x = -1 ; while (l<=r) { ll mid =(l+r)>>1; if(v2[mid]+it<=m) { x=mid; l=mid+1; } else r= mid-1; } if(x!=-1)ans+=(x+1); } cout<<ans<<endl; return 0 ; }

Compilation message (stderr)

bobek.cpp: In function 'void solve(long long int, long long int, std::vector<long long int>, std::vector<long long int>&)':
bobek.cpp:17:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(idx==arr.size() )
        ~~~^~~~~~~~~~~~
#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...