답안 #83852

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83852 2018-11-11T11:39:18 Z nikolapesic2802 Karte (COCI18_karte) C++14
120 / 120
524 ms 28816 KB
/*
    - Keep a variable k - how many cards need to be wrong until the end.
    - If there is a card with value k in our current set, pick it
    - else, If there is a card with a value greater than k, pick it and decrease k by 1.
    - else, pick the card with the lowest value and decrease k by 1.
    - Test if the cards we picked form a solution that is correct, if yes print it, if no print -1
*/
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back

int main()
{
    int n,k;
    scanf("%i %i",&n,&k);
    int t=k;
    multiset<int> karte;
    karte.insert(INT_MAX);
    for(int i=0;i<n;i++)
    {
        int a;
        scanf("%i",&a);
        karte.insert(a);
    }
    vector<int> sol;
    for(int i=0;i<n;i++)
    {
        int a=*karte.lower_bound(k);
        if(a==INT_MAX)
        {
            a=*karte.begin();
        }
        sol.pb(a);
        karte.erase(karte.find(a));
        if(a!=k)
            k--;
        continue;
    }
    int cnt=0;
    for(int i=n-1;i>=0;i--)
    {
        if(sol[i]>cnt)
            cnt++;
    }
    if(cnt==t)
    {
        for(int i=0;i<n;i++)
        {
            printf("%i ",sol[i]);
        }
    }
    else
    {
        printf("-1");
    }
    return 0;
}

Compilation message

karte.cpp: In function 'int main()':
karte.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %i",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~
karte.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&a);
         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 484 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 484 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 552 KB Output is correct
2 Correct 3 ms 552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 552 KB Output is correct
2 Correct 2 ms 580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 620 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 636 KB Output is correct
2 Correct 3 ms 652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 6528 KB Output is correct
2 Correct 86 ms 6528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 202 ms 11888 KB Output is correct
2 Correct 185 ms 11888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 524 ms 28816 KB Output is correct
2 Correct 498 ms 28816 KB Output is correct