Submission #74141

# Submission time Handle Problem Language Result Execution time Memory
74141 2018-08-30T09:38:53 Z jiaqing23 Zalmoxis (BOI18_zalmoxis) C++14
10 / 100
1000 ms 122084 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<ll> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;
typedef pair<int,pair<int,int> > tri;

int n, k;
int a[1000050];
set<pi> s;
set<int> pos;
multiset<int> s2;
vector<int> add[1000050];
int addnum = 0;
int need;

void split(int k){
    s2.insert(k);
    while(need){
        auto it = --s2.end();
        int i = *it;
        if(i==1) break;
        s2.erase(it);
        s2.insert(i-1);
        s2.insert(i-1);
        need--;
        //cout<<i<<' '<<i-1<<' '<<s2.size()<<endl;
    }
    for(auto i: s2) printf("%d ", i);
}

int main()
{
	//ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	for(int i = 0; i < n; i++){
        scanf("%d",&a[i]);
        s.insert(mp(a[i],i));
        pos.insert(i);
	}

	while(1){
        auto it = s.begin();
        pi p = *it;
        //cout<<p.fi<<endl;
        if(s.size()==1){
            if(p.fi==30) break;
            else{
                for(int i = p.fi; i <= 29; i++){
                    add[p.se].pb(i);
                    addnum++;
                }
                s.erase(it);
                s.insert(mp(30,p.se));
            }
        }
        else{
            auto it2 = ++it;
            pi next = *it2;
            it--;

            auto pos1 = pos.find(p.se);
            auto pos2 = ++pos1;
            //cout<<p.fi << ' '<<next.fi<<endl;
            if(p.fi == next.fi && *pos2 == next.se){
                s.erase(it2);
                pos.erase(next.se);
                s.erase(it);
                s.insert(mp(p.fi+1, p.se));
                //cout<<"size:"<<s.size()<<endl;
            }
            else{
                add[p.se].pb(p.fi);
                addnum ++;
                s.erase(it);
                s.insert(mp(p.fi+1, p.se));
            }
        }


	}

    need = k - addnum;
    for(int i = 0; i < n; i++){
        for(int j = add[i].size()-1; j >= 0; j--){
            if(need) split(add[i][j]);
            else
                printf("%d ",add[i][j]);
        }
        printf("%d ",a[i]);
        //cout<<endl;
    }

	return 0;
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1085 ms 121592 KB Time limit exceeded
2 Execution timed out 1082 ms 121752 KB Time limit exceeded
3 Execution timed out 1087 ms 121860 KB Time limit exceeded
4 Execution timed out 1081 ms 121980 KB Time limit exceeded
5 Execution timed out 1084 ms 121996 KB Time limit exceeded
6 Execution timed out 1080 ms 122000 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 122000 KB Time limit exceeded
2 Execution timed out 1085 ms 122000 KB Time limit exceeded
3 Execution timed out 1089 ms 122000 KB Time limit exceeded
4 Execution timed out 1081 ms 122000 KB Time limit exceeded
5 Execution timed out 1093 ms 122000 KB Time limit exceeded
6 Execution timed out 1086 ms 122084 KB Time limit exceeded
7 Execution timed out 1082 ms 122084 KB Time limit exceeded
8 Execution timed out 1092 ms 122084 KB Time limit exceeded
9 Execution timed out 1082 ms 122084 KB Time limit exceeded
10 Execution timed out 1037 ms 122084 KB Time limit exceeded
11 Execution timed out 1081 ms 122084 KB Time limit exceeded
12 Execution timed out 1018 ms 122084 KB Time limit exceeded
13 Correct 946 ms 122084 KB Output is correct
14 Correct 932 ms 122084 KB Output is correct