이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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=20;
vector<pair<int,int>> gl,hf;
for (int i=1;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)
gl.push_back({x,pre}),ans+=(x>=k);
}
sort(gl.rbegin(),gl.rend());
for (int i=1;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)
hf.push_back({x,fir}),ans+=(x>=k);
}
sort(hf.begin(),hf.end());
int id=0;
map<int,int> cnt;
for (auto i:hf)
{
while (id<gl.size() && gl[id].first>=k-i.first)
cnt[gl[id++].second]++;
for (auto j:cnt)
if (j.first<=i.second)
ans+=j.second;
else
break;
}
}
cout<<ans<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
san.cpp: In function 'int main()':
san.cpp:53:23: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
53 | for (int i=1;i<(1<<n-op);i++)
| ~^~~
san.cpp:75:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | while (id<gl.size() && gl[id].first>=k-i.first)
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |