Submission #68515

#TimeUsernameProblemLanguageResultExecution timeMemory
68515BruteforcemanZalmoxis (BOI18_zalmoxis)C++11
100 / 100
549 ms69408 KiB
#include <bits/stdc++.h>
using namespace std;
int a[1000010];
vector <int> v[1000010];
int alive[1000010];

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;
    vector <int> can;
    for(int i = 0; i < 30; i++) {
        can.clear();
        for(int j = 1; j <= n; j++) {
            if(alive[j]) can.emplace_back(j);
        }
        int size = can.size();
        for(int j = size - 1; j >= 0 && sz <= (n + k); j--) {
            if(alive[can[j]] == 0) continue;
            if(a[can[j]] == i) {
                if(j == 0 || a[can[j - 1]] != i) {
                    v[can[j]].emplace_back(i);
                    ++a[can[j]];
                    ++sz;
                } else {
                    alive[can[j - 1]] = 0;
                    ++a[can[j]];
                }
            }
        }
    }
    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 (stderr)

zalmoxis.cpp: In function 'int main(int, const char**)':
zalmoxis.cpp:10: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:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...