Submission #674030

# Submission time Handle Problem Language Result Execution time Memory
674030 2022-12-22T16:04:41 Z Victor Akcija (COCI21_akcija) C++17
30 / 110
3325 ms 524288 KB
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define debug(x) cout<<#x<<" = "<<x<<endl

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const int INF = 1'000'000'007;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    int n,k;
    cin>>n>>k;
    vector<iii> products(n);

    rep(i,0,n) {
        cin>>products[i].first>>products[i].second.first;
        products[i].second.second=i;
    }

    sort(all(products));
    int cnt=0;
    ll sum=0;
    vector<bool> taken(n,0);

   vector<iii> optimal;
    {
        int id=0;
        trav(product,products) {
            int cost=product.first,deadline,bla;
            tie(deadline,bla)=product.second;
            per(i,0,deadline) if(taken[i]==0) { 
                taken[i]=1;
                ++cnt;
                sum+=cost;
                optimal.pb({deadline,{cost,id}});
                break;
            } 
            ++id;
        }
    }

    per(i,0,sz(optimal)) {
        int id=optimal[i].second.second;
        products.erase(products.begin()+id);
    }

    sort(all(optimal));

    rep(i,0,n) swap(products[i].first,products[i].second.first);
    sort(all(optimal));
    rep(i,0,n) swap(products[i].first,products[i].second.first);

    cnt=0;
    int unique_id=1;

    //cout<<sz(products)<<endl;
    //trav(product,products) debug(product.first);

    map<pair<int,pair<ll,int>>,ii> nodes;
    nodes[{-sz(optimal),{sum,0}}]={0,0};
    while(cnt<k) {
        auto it=nodes.begin();

        int siz=-it->first.first;
        ll sum_cost=it->first.second.first;

        int product_index,pos_edit;
        tie(product_index,pos_edit)=it->second;

        nodes.erase(it);

        if(pos_edit%2==0) {
            //cout<<endl;
            //cout<<"siz = "<<siz<<" sum_cost = "<<sum_cost<<" product_index = "<<product_index<<" pos_edit = "<<pos_edit<<endl;
            cout<<siz<<' '<<sum_cost<<endl;
            ++cnt;
            if(cnt==k) break;
        }   

        int bla=pos_edit;
        pos_edit/=2;

        int pos_cost=0;
        if(pos_edit!=sz(optimal)) pos_cost=optimal[pos_edit].second.first;
        int product_cost=0;
        if(pos_edit!=sz(optimal)) product_cost=products[product_index].first;;

        //cout<<"siz = "<<siz<<" sum_cost = "<<sum_cost<<" product_index = "<<product_index<<" pos_edit = "<<bla<<" pos_cost = "<<pos_cost<<" product_cost = "<<product_cost<<endl;

        if(pos_edit!=sz(optimal)) {
            nodes[{-siz,{sum_cost,unique_id++}}]={product_index,(pos_edit+1)*2+1};
            nodes[{-(siz-1),{sum_cost-pos_cost,unique_id++}}]={product_index,(pos_edit+1)*2};
        }
        if(product_index!=sz(products)) nodes[{-siz,{sum_cost,unique_id++}}]={product_index+1,(pos_edit)*2+1}; // move product index

        int removed=sz(optimal)-siz;
        if(pos_edit!=sz(optimal)&&product_index!=sz(products)&&pos_edit-removed<products[product_index].second.first) nodes[{-siz,{sum_cost-pos_cost+product_cost,unique_id++}}]={product_index+1,(pos_edit+1)*2};
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:106:13: warning: unused variable 'bla' [-Wunused-variable]
  106 |         int bla=pos_edit;
      |             ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 360 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3325 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 12676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 360 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Runtime error 3325 ms 524288 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -