Submission #1025850

#TimeUsernameProblemLanguageResultExecution timeMemory
1025850vjudge1San (COCI17_san)C++17
72 / 120
1082 ms14780 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n,k; cin>>n>>k; int h[n],a[n]; for (int i=0;i<n;i++) cin>>h[i]>>a[i]; int ans=0; if (n<=20) { for (int i=0;i<(1<<n);i++) { bool b=1; int x=0,pre=0; for (int p=0;p<n;p++) if ((1<<p)&i) { if (h[p]<pre) b=0; pre=h[p]; x+=a[p]; } if (x>=k && b) ans++; } } else { map<int,vector<int>> mp; for (int i=0;i<(1<<20);i++) { bool b=1; int x=0,pre=0; for (int p=0;p<20;p++) if ((1<<p)&i) { if (h[p]<pre) b=0; pre=h[p]; x+=a[p]; } if (b) mp[pre].push_back(x),ans+=(x>=k); } for (auto &i:mp) sort(i.second.begin(),i.second.end()); for (int i=0;i<(1<<n-20);i++) { bool b=1; int x=0,pre=0,fir=0; for (int p=0;p<n-20;p++) if ((1<<p)&i) { if (h[p+20]<pre) b=0; x+=a[p+20]; pre=h[p+20]; if (!fir) fir=h[p+20]; } if (!b) continue; for (auto i:mp) if (i.first<=fir) { int y=lower_bound(i.second.begin(),i.second.end(),k-x)-i.second.begin(); ans+=i.second.size()-y; } else break; } } cout<<ans<<endl; return 0; }

Compilation message (stderr)

san.cpp: In function 'int main()':
san.cpp:53:23: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   53 |   for (int i=0;i<(1<<n-20);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...