답안 #726992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726992 2023-04-19T19:03:44 Z buffering Karte (COCI18_karte) C++17
120 / 120
122 ms 13892 KB
#include <bits/stdc++.h>
using namespace std;

void IO(string s = "")
{
    if (s == "")
    {
        freopen("input.txt", "r", stdin);
        freopen("output 2.txt", "w", stdout);
    }
    if (s != "")
    {
        freopen((s + ".in").c_str(), "r", stdin);
        freopen((s + ".out").c_str(), "w", stdout);
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    //IO();

    int n; int m;
    cin >> n >> m;

    vector<int> nums(n);
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
    }
    sort(nums.begin(), nums.end());

    int correct = n - m;

    vector<int> a;

    for (int i = correct - 1; i >= 0; i--) {
        a.push_back(nums[i]);
    }

    vector<int> b;

    for (int i = n - 1; i >= correct; i--) {
        b.push_back(nums[i]);
    }

    vector<int> vals;

    for (int x: a) vals.push_back(x);
    for (int x: b) vals.push_back(x);

    int bad = 0;

    for (int i = n - 1; i >= 0; i--) {
        if (vals[i] > bad) {
            bad++;
        }
    }

    if (bad == m) {
        for (int i = 0; i < n; i++) {
            cout<< vals[i] << " ";
        }
        cout << endl;
    }
    else cout << -1 << endl;

}

Compilation message

karte.cpp: In function 'void IO(std::string)':
karte.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
karte.cpp:9:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         freopen("output 2.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
karte.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
karte.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         freopen((s + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 3068 KB Output is correct
2 Correct 16 ms 2368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 5824 KB Output is correct
2 Correct 37 ms 4608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 13892 KB Output is correct
2 Correct 75 ms 11228 KB Output is correct