Submission #54742

# Submission time Handle Problem Language Result Execution time Memory
54742 2018-07-05T00:06:40 Z ksun48 Park (JOI17_park) C++14
20 / 100
354 ms 952 KB
#include <bits/stdc++.h>
#include "park.h"
using namespace std;

int P[1400];
int ask(int a, int b){
	if(P[a] == 0 || P[b] == 0) return 0;
	if(a == b) return 1;
	return Ask(min(a,b), max(a,b), P);
}

void found(int a, int b){
	Answer(min(a,b), max(a,b));
}

void solve1(int n){
	for(int i = 0; i < n; i++){
		P[i] = 0;
	}
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			P[i] = P[j] = 1;
			if(ask(i,j)){
				found(i,j);
			}
			P[i] = P[j] = 0;
		}
	}
}

int check_edge(int a, int b, int n){
	if(a == b) return 0;
	for(int i = 0; i < n; i++){
		P[i] = 0;
	}
	P[a] = P[b] = 1;
	return ask(a, b);
}

int check_subtree(int a, int b, int c, int n){
	// a-b is an edge, check if x == b or x is in b's side
	for(int i = 0; i < n; i++){
		P[i] = 1;
	}
	P[b] = 0;
	if(ask(a,c)){
		return 0;
	}
	return 1;
}
void solvetree(vector<int> v, int n){
	if(v.size() <= 1) return;
	while(1){
		int a = v[rand() % v.size()];
		int b = v[rand() % v.size()];

		if(!check_edge(a, b, n)){
			continue;
		}
		found(a,b);

		vector<int> v1;
		vector<int> v2;

		for(int x : v){
			if(check_subtree(a, b, x, n)){
				v1.push_back(x);
			} else {
				v2.push_back(x);
			}
		}
		solvetree(v1, n);
		solvetree(v2, n);
		assert(v1.size() < v.size() && v2.size() < v.size());
		return;
	}
}

void solvetreev(vector<int> v, int n){
	if(v.size() <= 1) return;
	int a = v[rand() % v.size()];
	vector<pair<int, vector<int> > > children;
	for(int x : v){
		if(check_edge(a, x, n)){
			found(a,x);
			children.push_back({x, vector<int>()});
		}
	}
	for(int x : v){
		if(x == a) continue;
		random_shuffle(children.begin(), children.end());
		for(int i = 0; i < children.size(); i++){
			if(check_subtree(a, children[i].first, x, n)){
				children[i].second.push_back(x);
				break;
			}
			assert(i + 1 != children.size());
		}
	}
	for(int i = 0; i < children.size(); i++){
		solvetreev(children[i].second, n);
	}
	return;
}

void solve2(int n){
	vector<int> v;
	for(int i = 0; i < n; i++){
		v.push_back(i);
	}
	solvetreev(v, n);
}
void Detect(int T, int N) {
	srand(48);
	if(T == 1){
		solve1(N);
	} else if(T >= 2){
		solve2(N);
	}
}

Compilation message

park.cpp: In function 'void solvetreev(std::vector<int>, int)':
park.cpp:92:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < children.size(); i++){
                  ~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from park.cpp:1:
park.cpp:97:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    assert(i + 1 != children.size());
           ~~~~~~^~~~~~~~~~~~~~~~~~
park.cpp:100:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < children.size(); i++){
                 ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 8 ms 356 KB Output is correct
3 Correct 8 ms 432 KB Output is correct
4 Correct 8 ms 468 KB Output is correct
5 Correct 8 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 740 KB Output is correct
2 Correct 213 ms 740 KB Output is correct
3 Correct 194 ms 740 KB Output is correct
4 Correct 354 ms 740 KB Output is correct
5 Correct 315 ms 944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 261 ms 944 KB Wrong Answer[5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 203 ms 944 KB Wrong Answer[5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 134 ms 952 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -