Submission #414262

# Submission time Handle Problem Language Result Execution time Memory
414262 2021-05-30T09:40:46 Z asdfaqdsa Shopping Plans (CCO20_day2problem3) C++14
0 / 25
681 ms 7052 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pld;
ll n, m, k;
ll sq = 65;
vector<ll> vec[4009];
vector<ll> pos[4009];
ll x[4009], y[4009];
void end(){
    while(k--)
        cout << "-1\n";
    exit(0);
}
ll calc(ll x){
    ll res = 1;
    for(ll i = 1; i <= m; ++i){
        ll cur = 1;
        for(ll j = 1; j < pos[i].size(); ++j){
            if(pos[i][j]-pos[i][j-1] <= x)
                ++cur;
            else
                break;
        }
        res = min((ll)1e9+7, res*cur);
    }
    return res;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
     
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
 
    cin >> n >> m >> k;
 
    for(ll i = 0; i < n; ++i){
        ll a, c;
        cin >> a >> c;
        vec[a].pb(c);
    }
    ll tot = 1;
    for(ll i = 1; i <= m; ++i){
        sort(all(vec[i]));
        cin >> x[i] >> y[i];    
        multiset<pii> cur;
        cur.insert({0, 0});
        for(ll j = 0; j < vec[i].size(); ++j){
            multiset<pii> ncur;
            for(auto u : cur){
                ncur.insert(u);
                if(u.ff-1 >= -y[i])
                    ncur.insert({u.ff-1, u.ss+vec[i][j]});
            }
            while(ncur.size() > k){
                auto it = ncur.end();
                --it;
                ncur.erase(it);
            }
            cur = ncur;
        }
        for(auto u : cur)
            if(u.ff == -x[i])
                pos[i].pb(u.ss);
        if(pos[i].empty())
            end();
        tot = min((ll)1e9+7, tot*(ll)pos[i].size());
    }
 
    ll l = 0, r = 1e18;
    while(l < r){
        ll m = (l+r)/2;
        if(calc(m) >= k)
            r = m;
        else
            l = m+1;
    }
    vector<ll> ans = {0};
    for(ll i = 1; i <= m; ++i){
        vector<ll> nans;
        for(ll j = 0; j < pos[i].size(); ++j){
            if(j != 0 && pos[i][j]-pos[i][j-1] > l)
                break;
            for(auto u : ans)
                nans.pb(u+pos[i][j]);
        }
        ans = nans;
    }
    sort(all(ans));
    if(ans.size() < k && tot >= k)
        assert(0);
    for(auto u : ans){
        if(k == 0) break;
        --k;
        cout << u << '\n';
    }
    end();
}

Compilation message

Main.cpp: In function 'll calc(ll)':
Main.cpp:29:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(ll j = 1; j < pos[i].size(); ++j){
      |                       ~~^~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:59:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(ll j = 0; j < vec[i].size(); ++j){
      |                       ~~^~~~~~~~~~~~~~~
Main.cpp:66:31: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   66 |             while(ncur.size() > k){
      |                   ~~~~~~~~~~~~^~~
Main.cpp:92:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |         for(ll j = 0; j < pos[i].size(); ++j){
      |                       ~~^~~~~~~~~~~~~~~
Main.cpp:101:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
  101 |     if(ans.size() < k && tot >= k)
      |        ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 681 ms 7052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 984 KB Output isn't correct
2 Halted 0 ms 0 KB -