Submission #95908

# Submission time Handle Problem Language Result Execution time Memory
95908 2019-02-03T13:16:16 Z JustInCase popa (BOI18_popa) C++17
100 / 100
80 ms 452 KB
#include <bits/stdc++.h>

#ifndef skeletaZaPrezident
#include "popa.h"
#endif

#define int32_t int
#define int64_t long long
#define Solve solve
#define Query query

const int32_t MAX_N = 1000;

int32_t parent[MAX_N + 5];

#ifdef skeletaZaPrezident
int32_t Query(int32_t a, int32_t b, int32_t c, int32_t d) {
	std::cout << a << " " << b << " " << c << " " << d << '\n' << std::flush;

	int32_t res;
	std::cin >> res;

	return res;
}
#endif

int32_t Solve(int32_t n, int32_t *left, int32_t *right) {
	memset(parent, -1, sizeof(parent));
	memset(left, -1, sizeof(left));
	memset(right, -1, sizeof(right));

	for(int32_t i = 0; i < n; i++) {
		left[i] = -1;
		right[i] = -1;
	}

	int32_t root = -1;
	for(int32_t i = 0; i < n; i++) {
		int32_t curr = i - 1;
		while(curr != -1 && Query(i, i, curr, i)) {
			right[curr] = left[i];
			parent[left[i]] = curr;
			left[i] = curr;
			int32_t nxt = parent[curr];
			parent[curr] = i;
			curr = nxt;
		}

		if(curr == -1) {
			left[i] = root;
			if(root != -1) {
				parent[root] = i;
			}
			root = i;
		}
		else {
			right[curr] = i;
			parent[i] = curr;
		}
	}

	return root;
}

#ifdef skeletaZaPrezident
int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int32_t left[6], right[6];
	int32_t ans = Solve(6, left, right);
	
	std::cout << ans << '\n';
	for(int32_t i = 0; i < 6; i++) {
		std::cout << left[i] << " " << right[i] << '\n';
	}
}
#endif

Compilation message

popa.cpp: In function 'int solve(int, int*, int*)':
popa.cpp:29:25: warning: argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
  memset(left, -1, sizeof(left));
                         ^
popa.cpp:30:26: warning: argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
  memset(right, -1, sizeof(right));
                          ^
# Verdict Execution time Memory Grader output
1 Correct 10 ms 248 KB Output is correct
2 Correct 10 ms 376 KB Output is correct
3 Correct 11 ms 376 KB Output is correct
4 Correct 11 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 376 KB Output is correct
2 Correct 70 ms 452 KB Output is correct
3 Correct 37 ms 328 KB Output is correct
4 Correct 72 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 324 KB Output is correct
2 Correct 52 ms 328 KB Output is correct
3 Correct 68 ms 448 KB Output is correct
4 Correct 80 ms 248 KB Output is correct