답안 #704322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704322 2023-03-02T03:36:35 Z minhnhatnoe Park (JOI17_park) C++14
47 / 100
240 ms 452 KB
#include <bits/stdc++.h>
#include "park.h"
using namespace std;
typedef long long ll;
void answer(int a, int b){
	Answer(min(a, b), max(a, b));
}
namespace subtask1{
	void solve(int n){
		for (int i=0; i<n; i++){
			for (int j=i+1; j<n; j++){
				vector<int> a(n, 0);
				a[i] = a[j] = 1;
				if (Ask(i, j, a.data())){
					answer(i, j);
				}
			}
		}
	}
};
bool in_middle(int n, int a, int b, int c){
	vector<int> place(n, 1);
	place[b] = 0;
	return Ask(min(a, c), max(a, c), place.data()) == 0;
}
namespace subtask2{
	void solve(int n){
		int idx1 = 0, idx2 = 1;
		for (int i=2; i<n; i++){
			if (in_middle(n, idx1, i, idx2)) continue;
			if (in_middle(n, idx1, idx2, i)){
				idx2 = i;
			}
			else{
				idx1 = i;
			}
		}
		vector<int> a;
		for (int i=0; i<n; i++){
			if (i != idx1) a.push_back(i);
		}
		sort(a.begin(), a.end(), [&](int x, int y){
			if (x == y) return false;
			return in_middle(n, idx1, x, y);
		});
		answer(idx1, a[0]);
		for (int i=1; i<a.size(); i++){
			answer(a[i-1], a[i]);
		}
	}
};
namespace subtask3{
	int find_root(int n, vector<int> &subtree){
		int root = subtree[0];
		for (int i=1; i<subtree.size(); i++){
			if (in_middle(n, root, subtree[i], 0)){
				root = subtree[i];
			}
		}
		return root;
	}
	void solve(int n, vector<int> &subtree, int root, bool is_troot){
		int mxsize = 6 + is_troot;
		vector<vector<int>> a;
		for (int u: subtree){
			if (u == root) continue;
			bool found = false;
			for (int i=0; i<a.size() && !found; i++){
				if (i == mxsize - 1 || !in_middle(n, u, root, a[i][0])){
					a[i].push_back(u);
					found = true;
				}
			}
			if (!found){
				a.push_back(vector<int>({u}));
			}
		}
		for (int i=0; i<a.size(); i++){
			int subroot = find_root(n, a[i]);
			answer(root, subroot);
			solve(n, a[i], subroot, false);
		}
	}
	void solve(int n){
		vector<int> tree(n); iota(tree.begin(), tree.end(), 0);
		solve(n, tree, 0, true);
	}
};
void Detect(int T, int N){
	if (T == 1){
		subtask1::solve(N);
	}
	else if (T == 2){
		subtask2::solve(N);
	}
	else if (T == 3){
		subtask3::solve(N);
	}
}

Compilation message

park.cpp: In function 'void subtask2::solve(int)':
park.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for (int i=1; i<a.size(); i++){
      |                 ~^~~~~~~~~
park.cpp: In function 'int subtask3::find_root(int, std::vector<int>&)':
park.cpp:55:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for (int i=1; i<subtree.size(); i++){
      |                 ~^~~~~~~~~~~~~~~
park.cpp: In function 'void subtask3::solve(int, std::vector<int>&, int, bool)':
park.cpp:68:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |    for (int i=0; i<a.size() && !found; i++){
      |                  ~^~~~~~~~~
park.cpp:78:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   for (int i=0; i<a.size(); i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 212 KB Output is correct
3 Correct 5 ms 324 KB Output is correct
4 Correct 5 ms 212 KB Output is correct
5 Correct 5 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 208 ms 440 KB Output is correct
2 Correct 89 ms 444 KB Output is correct
3 Correct 106 ms 340 KB Output is correct
4 Correct 209 ms 452 KB Output is correct
5 Correct 235 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 400 KB Output is correct
2 Correct 240 ms 392 KB Output is correct
3 Correct 190 ms 392 KB Output is correct
4 Correct 212 ms 408 KB Output is correct
5 Correct 190 ms 408 KB Output is correct
6 Correct 193 ms 340 KB Output is correct
7 Correct 211 ms 400 KB Output is correct
8 Correct 209 ms 400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Wrong Answer[6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Wrong Answer[6]
2 Halted 0 ms 0 KB -