Submission #65734

# Submission time Handle Problem Language Result Execution time Memory
65734 2018-08-08T15:28:47 Z Mamnoon_Siam Zalmoxis (BOI18_zalmoxis) C++17
Compilation error
0 ms 0 KB
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
// #include <bits/extc++.h>
using namespace std;

#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a, val) memset(a, val, sizeof (a))
#define PB push_back
#define endl '\n'
typedef long long ll;

inline int myrand(int l, int r) {
	int ret = rand(); ret <<= 15; ret ^= rand();
	if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
	return ret;
}

template <typename F, typename S>
ostream& operator << (ostream& os, const pair< F, S>& p) {
	return os<<"(" <<p.first<<", "<<p.second<<")"; }

typedef pair<int, int> ii;

template<typename T> using min_pq =
	std::priority_queue<T, vector<T>, greater<T> >;

//int dx[] = {-1, +0, +1, +0};
//int dy[] = {+0, +1, +0, -1};

const int maxn = 2000005;

vector<int> v, nodes;
set<int> st;
int n, k;
int it = 0;

void dfs(int u, int lvl) {
	if(lvl == v[it]) {
		nodes.emplace_back(u);
		it++;
		return;
	}
	dfs(u << 1, lvl - 1);
	if(it == v.size() or lvl <= v[it]) {
		others.emplace_back(u << 1 | 1);
		return;
	}
	dfs(u << 1 | 1, lvl - 1);
}

void print(int u, int lvl) {
	if(binary_search(nodes.begin(), nodes.end(), u)) {
		cout << lvl << ' ';
		return;
	}
	print(u << 1, lvl - 1);
	print(u << 1 | 1, lvl - 1);
}

int32_t main () {
	// freopen("in", "r", stdin);
    cin >> n >> k;
    v.resize(n);
    for(int &b : v) cin >> b;
    dfs(1, 30);
	set<int> st(others.begin(), others.end());
	while(st.size() < k) {
		int top = *st.begin();
		st.erase(st.begin());
		st.insert(top << 1);
		st.insert(top << 1 | 1);
	}
	others.clear();
	for(int b : st) {
		nodes.emplace_back(b);
	}
	sort(nodes.begin(), nodes.end());
	print(1, 30);
	cout << endl;
}

Compilation message

zalmoxis.cpp: In function 'int myrand(int, int)':
zalmoxis.cpp:18:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
  ^~
zalmoxis.cpp:18:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
                          ^~~
zalmoxis.cpp: In function 'void dfs(int, int)':
zalmoxis.cpp:48:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(it == v.size() or lvl <= v[it]) {
     ~~~^~~~~~~~~~~
zalmoxis.cpp:49:3: error: 'others' was not declared in this scope
   others.emplace_back(u << 1 | 1);
   ^~~~~~
zalmoxis.cpp:49:3: note: suggested alternative: 'stderr'
   others.emplace_back(u << 1 | 1);
   ^~~~~~
   stderr
zalmoxis.cpp: In function 'int32_t main()':
zalmoxis.cpp:70:14: error: 'others' was not declared in this scope
  set<int> st(others.begin(), others.end());
              ^~~~~~
zalmoxis.cpp:70:14: note: suggested alternative: 'stderr'
  set<int> st(others.begin(), others.end());
              ^~~~~~
              stderr
zalmoxis.cpp:71:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(st.size() < k) {
        ~~~~~~~~~~^~~