제출 #68439

#제출 시각아이디문제언어결과실행 시간메모리
68439BruteforcemanZalmoxis (BOI18_zalmoxis)C++11
15 / 100
1097 ms92132 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;
    while(sz < n + k) {
        int opt = -1;
        for(int i = 1; i <= n; i++) {
            if(alive[i] == 1) {
                if(opt == -1 || a[opt] >= a[i]) {
                    opt = i;
                }
            }
        }
        if(a[opt] == 30) break;
        int prev = -1;
        for(int i = opt - 1; i >= 1; i--) {
            if(alive[i] == 1) {
                prev = i;
                break;
            }
        }
        if(prev == -1 || a[prev] > a[opt]) {
            v[opt].emplace_back(a[opt]);
            ++a[opt];
            ++sz;
        } else {
            alive[prev] = 0;
            ++a[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;
}

컴파일 시 표준 에러 (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...