답안 #483374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483374 2021-10-29T00:41:51 Z robell Karte (COCI18_karte) C++14
120 / 120
100 ms 7360 KB
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long ll;
#define pb push_back
#define eb emplace_back
#define countbits __builtin_popcount
#define beg0 __builtin_clz
#define terminal0 __builtin_ctz
#define f first
#define s second
int mod=1e9+7;
void setIO(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}
void setIO(string f){
	freopen((f+".in").c_str(),"r",stdin);
	freopen((f+".out").c_str(),"w",stdout);
	setIO();
}
int N, K, a[(int)5e5];
int main(){
   	setIO();
	cin >> N >> K;
	for (int i=0;i<N;i++) cin >> a[i];
	int z = 0;
	for (int i=0;i<N;i++){
		if (!a[i]) z++;
	}
	sort(a,a+N);
	if (N-z<K) cout << "-1\n";
	else if (z==N && !K){
		for (int i=0;i<N;i++) cout << "0 ";
		cout << "\n";
	}else if (!K){
		cout << "-1\n";
	}else{
		vector<int> n;
		for (int i=N-K;i<N;i++){
			n.pb(a[i]);
		}
		for (int i=0;i<N-K;i++){
			n.pb(a[i]);
		}
		int check = 0;
		for (int i=0;i<N;i++){
			if (check<n[i]) check++;
		}
		if (check!=K) cout << "-1\n";
		else{
			reverse(n.begin(),n.end());
			for (int i=0;i<N;i++) cout << n[i] << " ";
			cout << "\n";
		}
	}
}

Compilation message

karte.cpp: In function 'void setIO(std::string)':
karte.cpp:21:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  freopen((f+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
karte.cpp:22:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  freopen((f+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 1732 KB Output is correct
2 Correct 15 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 2928 KB Output is correct
2 Correct 28 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 6864 KB Output is correct
2 Correct 83 ms 7360 KB Output is correct