Submission #155373

# Submission time Handle Problem Language Result Execution time Memory
155373 2019-09-27T16:58:04 Z Charis02 Zalmoxis (BOI18_zalmoxis) C++14
45 / 100
1000 ms 159372 KB
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 2000004
#define INF 1e9+7

using namespace std;

ll n,k,ar[N],orig[N];
set < pi > s;
ll epomeno[N],proigoumeno[N];
vector < pi > res;
multiset < pi > varta;
multiset < pi > answers;

void solve()
{
    if((*s.begin()).first == 30)
        return;

    set < pi >::iterator it = s.begin();
    pi cur = *it;
    swap(cur.first,cur.second);

   // cout << cur.first << " " << cur.second << endl;

    if(epomeno[cur.first] != n && ar[epomeno[cur.first]] == cur.second)
    {
        epomeno[cur.first] = epomeno[epomeno[cur.first]];
        s.erase(s.begin());
    }
    else
    {
        res.push_back(cur);
    }

    s.erase(s.begin());
    s.insert(mp(cur.second+1,cur.first));
    ar[cur.first]++;

    solve();

    return;
}

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n >> k;

    rep(i,0,n)
    {
        cin >> ar[i];
        orig[i] = ar[i];
        epomeno[i] = i+1;
        proigoumeno[i+1] = i;
        s.insert(mp(ar[i],i));
    }

    solve();

    ll cur = 0;
    ll sz = res.size();
    ll start = 0;

    while(sz < k)
    {
        if(res[start].second == 0)
        {
            start++;
            continue;
        }

        res[start].second--;
        res.push_back(res[start]);

        sz++;
    }

    sort(res.begin(),res.end());

    rep(i,0,n)
    {
        while(cur < k && res[cur].first <= i)
        {
            cout << res[cur].second << " ";
            cur++;
        }

        cout << orig[i] << " ";
    }

    cout << endl;

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 849 ms 159096 KB Output is correct
2 Correct 912 ms 159372 KB Output is correct
3 Correct 898 ms 159108 KB Output is correct
4 Correct 854 ms 159180 KB Output is correct
5 Correct 873 ms 159072 KB Output is correct
6 Correct 853 ms 158992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1012 ms 159004 KB Time limit exceeded
2 Correct 914 ms 159136 KB Output is correct
3 Incorrect 931 ms 159012 KB not a zalsequence
4 Incorrect 950 ms 159000 KB not a zalsequence
5 Correct 943 ms 159168 KB Output is correct
6 Correct 975 ms 159144 KB Output is correct
7 Execution timed out 1008 ms 159132 KB Time limit exceeded
8 Execution timed out 1020 ms 159192 KB Time limit exceeded
9 Incorrect 840 ms 139252 KB not a zalsequence
10 Incorrect 442 ms 68880 KB not a zalsequence
11 Incorrect 597 ms 93000 KB not a zalsequence
12 Incorrect 145 ms 18176 KB not a zalsequence
13 Incorrect 153 ms 18168 KB not a zalsequence
14 Incorrect 149 ms 18168 KB not a zalsequence