Submission #61894

# Submission time Handle Problem Language Result Execution time Memory
61894 2018-07-27T04:38:01 Z alex(#2140) Zalmoxis (BOI18_zalmoxis) C++11
35 / 100
1000 ms 96744 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--;
        }
    }
    assert(a.size() == 1);

    int x = a.front().x;
    auto &r = a.front().l;

    for(i = 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 864 ms 96376 KB Output is correct
2 Correct 889 ms 96520 KB Output is correct
3 Correct 856 ms 96588 KB Output is correct
4 Correct 903 ms 96588 KB Output is correct
5 Correct 887 ms 96712 KB Output is correct
6 Correct 968 ms 96712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 990 ms 96712 KB not a zalsequence
2 Correct 895 ms 96712 KB Output is correct
3 Execution timed out 1016 ms 96712 KB Time limit exceeded
4 Incorrect 989 ms 96744 KB not a zalsequence
5 Execution timed out 1080 ms 96744 KB Time limit exceeded
6 Execution timed out 1042 ms 96744 KB Time limit exceeded
7 Incorrect 971 ms 96744 KB not a zalsequence
8 Incorrect 950 ms 96744 KB not a zalsequence
9 Execution timed out 1058 ms 96744 KB Time limit exceeded
10 Incorrect 764 ms 96744 KB not a zalsequence
11 Incorrect 969 ms 96744 KB not a zalsequence
12 Incorrect 190 ms 96744 KB not a zalsequence
13 Incorrect 189 ms 96744 KB not a zalsequence
14 Incorrect 168 ms 96744 KB not a zalsequence