답안 #668192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
668192 2022-12-03T08:37:38 Z mdubaisi Zalmoxis (BOI18_zalmoxis) C++14
0 / 100
57 ms 12364 KB
#include <bits/stdc++.h>
#include <array>
#include <unordered_set>
#define ll long long
#define all(v) (v.begin()), (v.end())
#define setall(a, val) for(auto& x : a) x = val
clock_t start_time;
double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; }
void init() {
#ifndef ONLINE_JUDGE
	FILE* _ = freopen("in.txt", "r", stdin);
	start_time = clock();
#endif
}
const ll MOD = 1e9 + 7;
const ll N = 1e6 + 7;
const ll M = 5e1 + 7;
using namespace std;
//####################################################################################

int n, k;
int a[N], pos;
vector< pair<bool, bool> > v; // {go to childeren, new node}
void create_tree(int x, int node) {
	if (!x || pos >= n)
		return;
	if (x == a[pos]) {
		v[node] = { 0, 0 };
		pos++;
		return;
	}
	if (a[pos] < x) {
		create_tree(x - 1, node * 2);
		create_tree(x - 1, node * 2 + 1);
		v[node] = { 1, 0 };
	}
	else
		v[node] = { 0, 1 }, k--;
}

void print(int x, int t) {
	if (!t) {
		cout << x << ' ';
		return;
	}
	print(x - 1, 0);
	print(x - 1, t - 1);
}

void solve(int x, int node) {
	if (!x)
		return;
	if (!v[node].first) {
		print(x, k * v[node].second);
		return;
	}
	solve(x - 1, node * 2);
	solve(x - 1, node * 2 + 1);
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);// init(); srand(time(0));

	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	v.resize(N);
	create_tree(30, 1);
	solve(30, 1);
	cout << endl;

	//cerr << get_time() << "s" << endl;
}

Compilation message

zalmoxis.cpp: In function 'void init()':
zalmoxis.cpp:11:8: warning: unused variable '_' [-Wunused-variable]
   11 |  FILE* _ = freopen("in.txt", "r", stdin);
      |        ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 50 ms 12276 KB Execution killed with signal 11
2 Runtime error 50 ms 12272 KB Execution killed with signal 11
3 Runtime error 50 ms 12348 KB Execution killed with signal 11
4 Runtime error 55 ms 12312 KB Execution killed with signal 11
5 Runtime error 51 ms 12296 KB Execution killed with signal 11
6 Runtime error 51 ms 12328 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 51 ms 12268 KB Execution killed with signal 11
2 Runtime error 50 ms 12308 KB Execution killed with signal 11
3 Runtime error 53 ms 12280 KB Execution killed with signal 11
4 Runtime error 56 ms 12284 KB Execution killed with signal 11
5 Runtime error 51 ms 12260 KB Execution killed with signal 11
6 Runtime error 57 ms 12360 KB Execution killed with signal 11
7 Runtime error 51 ms 12364 KB Execution killed with signal 11
8 Runtime error 51 ms 12288 KB Execution killed with signal 11
9 Runtime error 41 ms 10816 KB Execution killed with signal 11
10 Runtime error 18 ms 6732 KB Execution killed with signal 11
11 Runtime error 27 ms 8388 KB Execution killed with signal 11
12 Runtime error 4 ms 4436 KB Execution killed with signal 11
13 Runtime error 3 ms 4436 KB Execution killed with signal 11
14 Runtime error 4 ms 4436 KB Execution killed with signal 11