Submission #856113

# Submission time Handle Problem Language Result Execution time Memory
856113 2023-10-02T16:53:36 Z Benmath Zalmoxis (BOI18_zalmoxis) C++14
100 / 100
493 ms 139704 KB
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
int niz[1000001];
int n;
int k;
int vis[1000001];
vector<int>solve(int x, int y){
    
    if (y == 1){
        vector<int>ans;
        ans.push_back(x);
        return ans;
    }else if(y == 2){
        vector<int>ans;
        ans.push_back(x-1);
        ans.push_back(x-1);
        return ans;
    }else{
        if(x == 1){
            vector<int>ans;
            ans.push_back(0);
            ans.push_back(0);
            return ans;
        }
        vector<int> ro1 = solve(x - 1, y - 1);
        vector<int> ro2 = solve(x - 1, y - ro1.size());
        for(int i = 0; i < ro2.size();i++){
            ro1.push_back(ro2[i]);
        }
        return ro1;
    }
}
using pii = pair<int,pair<int,int>>;
int main()
{
    cin >> n >> k;
    vector<int>v[n];
    priority_queue<pii, vector<pii> , greater<pii> > pq;
    for(int i = 0; i < n; i++){
        cin >> niz[i];
        pq.push({niz[i],{i,i}});
    }
    int t1 = 0;
    while(!pq.empty() and t1 < k){
        pii a = pq.top();
        
        pq.pop();
        if(a.first < 30){
        if(pq.empty()){
            v[a.second.second].push_back(a.first);
            pq.push({a.first + 1, {a.second.first, a.second.second}});
            t1++;
        }else{
            pii b = pq.top();
            pq.pop();
            if(a.first != b.first){
                v[a.second.second].push_back(a.first);
                pq.push({a.first + 1, {a.second.first, a.second.second}});
                pq.push({b.first, {b.second.first,b.second.second}});
                t1++;
            }else{
                int prvi = a.second.second + 1;
                int drugi = b.second.first;
                if(prvi == drugi){
                    pq.push({a.first + 1,{a.second.first,b.second.second}});
                }else{
                    v[a.second.second].push_back(a.first);
                    pq.push({a.first + 1, {a.second.first, a.second.second}});
                    pq.push({b.first, {b.second.first,b.second.second}});
                    t1++;
                }
            }
        }
        }
    }
    k = k - t1;
    
    for(int i = 0; i < n; i++){
        cout << niz[i] << " ";
        for(int j = 0;j < v[i].size(); j++){
            
            vector<int> ro = solve(v[i][j], k + 1);
            for(int t = 0; t < ro.size(); t++){
                cout<<ro[t]<<" ";
            }
            int velicina = ro.size();
            k = k - (velicina - 1);
        }
    }
}

Compilation message

zalmoxis.cpp: In function 'std::vector<int> solve(int, int)':
zalmoxis.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int i = 0; i < ro2.size();i++){
      |                        ~~^~~~~~~~~~~~
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:89:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for(int j = 0;j < v[i].size(); j++){
      |                       ~~^~~~~~~~~~~~~
zalmoxis.cpp:92:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |             for(int t = 0; t < ro.size(); t++){
      |                            ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 487 ms 43456 KB Output is correct
2 Correct 468 ms 43440 KB Output is correct
3 Correct 480 ms 43256 KB Output is correct
4 Correct 473 ms 43308 KB Output is correct
5 Correct 493 ms 43484 KB Output is correct
6 Correct 471 ms 43656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 473 ms 43448 KB Output is correct
2 Correct 474 ms 43436 KB Output is correct
3 Correct 483 ms 43344 KB Output is correct
4 Correct 487 ms 43436 KB Output is correct
5 Correct 490 ms 43576 KB Output is correct
6 Correct 480 ms 43392 KB Output is correct
7 Correct 470 ms 43668 KB Output is correct
8 Correct 471 ms 43440 KB Output is correct
9 Correct 460 ms 39740 KB Output is correct
10 Correct 280 ms 80444 KB Output is correct
11 Correct 335 ms 28852 KB Output is correct
12 Correct 160 ms 139704 KB Output is correct
13 Correct 164 ms 139664 KB Output is correct
14 Correct 96 ms 9128 KB Output is correct