답안 #68483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68483 2018-08-17T08:09:44 Z Bruteforceman Zalmoxis (BOI18_zalmoxis) C++11
20 / 100
1000 ms 118112 KB
#include <bits/stdc++.h>
using namespace std;
int a[1000010];
vector <int> v[1000010];
int alive[1000010];

struct data {
    int val, idx;
    data (int val, int idx) : val(val), idx(idx) {}
    data () {}
    bool operator < (data p) const {
        if(val == p.val) return idx < p.idx;
        return val > p.val;
    }
};

int main(int argc, char const *argv[])
{
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        alive[i] = 1;
        v[i].emplace_back(a[i]);
    }
    int sz = n;
    set <int> s;
    priority_queue <data> Q;
    for(int i = 1; i <= n; i++) {
        Q.emplace(a[i], i);
        s.insert(i);
    }
    while(sz < n + k) {
        while(alive[Q.top().idx] == 0) {
            Q.pop();
        }
        int opt = Q.top().idx;
        Q.pop();

        if(a[opt] == 30) break;
        int prev;
        auto it = s.lower_bound(opt);
        if(it == s.begin()) prev = -1;
        else prev = *(--it);

        if(prev == -1 || a[prev] > a[opt]) {
            v[opt].emplace_back(a[opt]);
            ++a[opt];
            ++sz;
            Q.emplace(a[opt], opt);
        } else {
            alive[prev] = 0;
            s.erase(prev);
            ++a[opt];
            Q.emplace(a[opt], opt);
        }
    }
    for(int i = 1; i <= n; i++) {
        vector <int> tmp;
        while(v[i].size() > 1 && sz < n + k) {
            if(v[i].back() > 0) {
                int x = v[i].back();
                v[i].pop_back();
                v[i].emplace_back(x - 1);
                v[i].emplace_back(x - 1);
                ++sz;   
            } else {
                v[i].pop_back();
                tmp.emplace_back(0);
            }
        }
        for(auto j : tmp) {
            v[i].emplace_back(j);
        }
        for(auto j : v[i]) {
            printf("%d ", j);
        }
    }
    printf("\n");
    return 0;
}

Compilation message

zalmoxis.cpp: In function 'int main(int, const char**)':
zalmoxis.cpp:20: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:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1102 ms 117712 KB Time limit exceeded
2 Execution timed out 1094 ms 117948 KB Time limit exceeded
3 Execution timed out 1095 ms 117948 KB Time limit exceeded
4 Execution timed out 1102 ms 118008 KB Time limit exceeded
5 Execution timed out 1092 ms 118008 KB Time limit exceeded
6 Execution timed out 1097 ms 118008 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1084 ms 118008 KB Time limit exceeded
2 Execution timed out 1100 ms 118008 KB Time limit exceeded
3 Execution timed out 1091 ms 118008 KB Time limit exceeded
4 Execution timed out 1089 ms 118112 KB Time limit exceeded
5 Execution timed out 1076 ms 118112 KB Time limit exceeded
6 Execution timed out 1080 ms 118112 KB Time limit exceeded
7 Execution timed out 1089 ms 118112 KB Time limit exceeded
8 Execution timed out 1080 ms 118112 KB Time limit exceeded
9 Execution timed out 1077 ms 118112 KB Time limit exceeded
10 Correct 703 ms 118112 KB Output is correct
11 Execution timed out 1090 ms 118112 KB Time limit exceeded
12 Correct 155 ms 118112 KB Output is correct
13 Correct 182 ms 118112 KB Output is correct
14 Correct 136 ms 118112 KB Output is correct