# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1025877 |
2024-07-17T10:56:08 Z |
vjudge1 |
San (COCI17_san) |
C++17 |
|
1000 ms |
29112 KB |
#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
{
int op=21;
unordered_map<int,vector<int>> mp;
for (int i=0;i<(1<<op);i++)
{
bool b=1;
int x=0,pre=0;
for (int p=0;p<op;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-op);i++)
{
bool b=1;
int x=0,pre=0,fir=0;
for (int p=0;p<n-op;p++)
if ((1<<p)&i)
{
if (h[p+op]<pre)
b=0;
x+=a[p+op];
pre=h[p+op];
if (!fir)
fir=h[p+op];
}
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;
}
}
}
cout<<ans<<endl;
return 0;
}
Compilation message
san.cpp: In function 'int main()':
san.cpp:54:23: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
54 | for (int i=0;i<(1<<n-op);i++)
| ~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
348 KB |
Output is correct |
2 |
Correct |
66 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1020 ms |
29112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1064 ms |
3784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1043 ms |
12796 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |