Submission #155376

# Submission time Handle Problem Language Result Execution time Memory
155376 2019-09-27T17:04:05 Z Charis02 Zalmoxis (BOI18_zalmoxis) C++14
55 / 100
906 ms 108304 KB
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll int
#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];
vector < pi > res;

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

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

    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;
        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 783 ms 108188 KB Output is correct
2 Correct 859 ms 108248 KB Output is correct
3 Correct 864 ms 108272 KB Output is correct
4 Correct 829 ms 108264 KB Output is correct
5 Correct 819 ms 108280 KB Output is correct
6 Correct 852 ms 108184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 864 ms 108244 KB not a zalsequence
2 Correct 840 ms 108304 KB Output is correct
3 Incorrect 802 ms 108140 KB not a zalsequence
4 Incorrect 860 ms 108260 KB not a zalsequence
5 Correct 848 ms 108188 KB Output is correct
6 Correct 860 ms 108264 KB Output is correct
7 Correct 906 ms 108224 KB Output is correct
8 Correct 879 ms 108252 KB Output is correct
9 Incorrect 824 ms 95084 KB not a zalsequence
10 Incorrect 390 ms 40752 KB not a zalsequence
11 Incorrect 539 ms 62920 KB not a zalsequence
12 Incorrect 132 ms 10324 KB not a zalsequence
13 Incorrect 131 ms 10452 KB not a zalsequence
14 Incorrect 131 ms 10448 KB not a zalsequence