답안 #50599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50599 2018-06-11T21:29:34 Z XmtosX San (COCI17_san) C++17
96 / 120
1000 ms 127844 KB
#include <bits/stdc++.h>
using namespace std;
vector <long long> v2[40];
vector <pair<long long ,int> > v1;
int n;
long long k,h[50],c[50];
void bt (int pos,int x,long long first,int last,long long sum)
{
    if (pos==x)
    {
        if (x!=n+1)
            v1.push_back({sum,last});
        else
        {
            for (int i=0;i<=n/2;i++)
                if (first>=h[i]) v2[i].push_back(sum);
        }
        return ;
    }
    if (h[pos]>=h[last])
        bt(pos+1,x,min(first,h[pos]),pos,sum+c[pos]);
    bt(pos+1,x,first,last,sum);
}
int main()
{
    cin >>n>>k;
    for (int i=1;i<=n;i++)
        cin >>h[i]>>c[i];
    bt(1,n/2+1,1e18,0,0);
    bt(n/2+1,n+1,1e18,0,0);
    for (int i=0;i<=n/2;i++)
        sort(v2[i].begin(),v2[i].end());
    long long ans=0;
    for (int i=0;i<v1.size();i++)
    {
        int idx= v1[i].second;
        long long sum= v1[i].first;
        sum= (k-sum);
        int p1= lower_bound(v2[idx].begin(),v2[idx].end(),sum)-v2[idx].begin();
        ans+= (v2[idx].size()-p1);
    }
    cout <<ans;
    return 0;
}

Compilation message

san.cpp: In function 'int main()':
san.cpp:34:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<v1.size();i++)
                  ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 488 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 9832 KB Output is correct
2 Correct 7 ms 9832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 224 ms 26736 KB Output is correct
2 Correct 11 ms 26736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 127844 KB Time limit exceeded
2 Halted 0 ms 0 KB -