답안 #83847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83847 2018-11-11T11:30:24 Z nikolapesic2802 Karte (COCI18_karte) C++14
0 / 120
792 ms 66560 KB
/*
    - Keep a variable k- how many cards need to be wrong until the end.
    
*/
#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;
    multiset<int,greater<int> > revkarte;
    revkarte.insert(-1);
    karte.insert(INT_MAX);
    for(int i=0;i<n;i++)
    {
        int a;
        scanf("%i",&a);
        karte.insert(a);
        revkarte.insert(a);
    }
    vector<int> choose;
    for(int i=0;i<n;i++)
    {
        int a=*karte.lower_bound(k);
        if(a>=k)
        {
            choose.pb(a);
            karte.erase(karte.find(a));
            revkarte.erase(revkarte.find(a));
            if(a>k)
                k--;
            continue;
        }
        if(a==INT_MAX)
        {
            int b=*revkarte.upper_bound(k-1);
            if(b==-1)
            {
                karte.erase(karte.find(k-1));
                revkarte.erase(revkarte.find(k-1));
                choose.pb(k-1);
                k--;
                continue;
            }
            choose.pb(b);
            karte.erase(karte.find(b));
            revkarte.erase(revkarte.find(b));
            k--;
            continue;
        }
    }
    int tr=0;
    int cnt=0;
    for(int i=n-1;i>=0;i--)
    {
        //printf("%i ",choose[i]);
        if(choose[i]<=tr)
        {
            continue;
        }
        cnt++;
        tr++;
    }
    if(cnt==t)
    {
        for(int i=0;i<n;i++)
        {
            printf("%i ",choose[i]);
        }
    }
    else
    {
        printf("-1");
    }
    return 0;
}

Compilation message

karte.cpp: In function 'int main()':
karte.cpp:15: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:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&a);
         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 852 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1048 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1208 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 1208 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 139 ms 19964 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 312 ms 39456 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 792 ms 66560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -