Submission #61902

# Submission time Handle Problem Language Result Execution time Memory
61902 2018-07-27T04:51:58 Z alex(#2140) Zalmoxis (BOI18_zalmoxis) C++11
95 / 100
1000 ms 96696 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

struct node
{
    int x;
    list<int> l;
};

list<node> a;

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, k, i;
    scanf("%d%d", &n, &k);
    for(i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        a.push_back({ x, list<int>(1, x) });
    }

    int c = 0;
    for(i = 0; i < 30; i++)
    {
        for(auto it = a.begin(); it != a.end(); it++)
        {
            if(abs(it->x) != i)
                continue;

            auto it2 = next(it);
            if(it2 != a.end() && abs(it2->x) == i)
            {
                it->l.splice(it->l.end(), it2->l);
                a.erase(it2);
            }
            else
            {
                c++;
                it->l.push_back(-abs(it->x));
            }

            if(it->x > 0)
                (it->x)++;
            else
                (it->x)--;
        }
    }

    auto &r = a.front().l;
    for(i = abs(a.front().x); i < 30; i++)
    {
        c++;
        r.push_back(-i);
    }

    for(auto it = r.begin(); it != r.end(); it++)
    {
        while(*it < 0 && c < k)
        {
            c++;
            (*it)++;
            r.insert(next(it), *it);
        }
    }

    for(auto it = r.begin(); it != r.end(); it++)
        printf("%d ", abs(*it));
    return 0;
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
zalmoxis.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 755 ms 96232 KB Output is correct
2 Correct 953 ms 96376 KB Output is correct
3 Correct 810 ms 96540 KB Output is correct
4 Correct 796 ms 96544 KB Output is correct
5 Correct 927 ms 96544 KB Output is correct
6 Correct 751 ms 96544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 944 ms 96608 KB Output is correct
2 Correct 888 ms 96608 KB Output is correct
3 Correct 936 ms 96608 KB Output is correct
4 Correct 892 ms 96608 KB Output is correct
5 Execution timed out 1002 ms 96608 KB Time limit exceeded
6 Correct 945 ms 96696 KB Output is correct
7 Correct 918 ms 96696 KB Output is correct
8 Correct 891 ms 96696 KB Output is correct
9 Correct 827 ms 96696 KB Output is correct
10 Correct 789 ms 96696 KB Output is correct
11 Correct 845 ms 96696 KB Output is correct
12 Correct 201 ms 96696 KB Output is correct
13 Correct 277 ms 96696 KB Output is correct
14 Correct 201 ms 96696 KB Output is correct