Submission #483373

# Submission time Handle Problem Language Result Execution time Memory
483373 2021-10-29T00:38:30 Z robell Karte (COCI18_karte) C++14
0 / 120
64 ms 4416 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 col, check = 0;
		for (int i=0;i<N;i++){
			if (col<n[i]) col++,check++;
		}
		if (check!=K) cout << "-1\n";
		else{
			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);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
karte.cpp: In function 'int main()':
karte.cpp:51:23: warning: 'col' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |    if (col<n[i]) col++,check++;
      |                  ~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 1360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 2248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 4416 KB Output isn't correct
2 Halted 0 ms 0 KB -