답안 #61912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61912 2018-07-27T05:07:25 Z alex(#2140) Zalmoxis (BOI18_zalmoxis) C++11
80 / 100
1000 ms 65548 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>
#include <forward_list>

using namespace std;

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

forward_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_front({ x, forward_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_after(it->l.before_begin(), it2->l);
                a.erase_after(it);
            }
            else
            {
                c++;
                it->l.push_front(-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_front(-i);
    }

    for(auto it = r.begin(); it != r.end(); it++)
    {
        while(*it < 0 && c < k)
        {
            c++;
            (*it)++;
            r.insert_after(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:35: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:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 934 ms 65272 KB Output is correct
2 Correct 972 ms 65272 KB Output is correct
3 Correct 987 ms 65272 KB Output is correct
4 Correct 963 ms 65272 KB Output is correct
5 Correct 934 ms 65272 KB Output is correct
6 Correct 956 ms 65272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1049 ms 65272 KB Time limit exceeded
2 Correct 835 ms 65272 KB Output is correct
3 Execution timed out 1057 ms 65272 KB Time limit exceeded
4 Execution timed out 1069 ms 65324 KB Time limit exceeded
5 Correct 971 ms 65324 KB Output is correct
6 Execution timed out 1008 ms 65324 KB Time limit exceeded
7 Correct 871 ms 65548 KB Output is correct
8 Correct 931 ms 65548 KB Output is correct
9 Correct 945 ms 65548 KB Output is correct
10 Correct 482 ms 65548 KB Output is correct
11 Correct 676 ms 65548 KB Output is correct
12 Correct 173 ms 65548 KB Output is correct
13 Correct 168 ms 65548 KB Output is correct
14 Correct 267 ms 65548 KB Output is correct