Submission #466438

# Submission time Handle Problem Language Result Execution time Memory
466438 2021-08-19T09:35:39 Z prvocislo Chameleon's Love (JOI20_chameleon) C++17
40 / 100
10 ms 712 KB
#include "chameleon.h"
#include <vector>
#include <iostream>
using namespace std;

const int maxn = 505;
vector<int> g[maxn * 2];
vector<pair<int, int>> v;
bool vis[maxn];
int query(int x, vector<int> a)
{
	a.push_back(x);
	return Query(a);
}
void find_edges(int x, const vector<int> &a)
{
	if (!a.size()) return;
	if (a.size() == 1)
	{
		//cout << x << " " << a[0] << "\n";
		if (query(x, a) == 1) g[x].push_back(a[0]), g[a[0]].push_back(x);
		return;
	}
	vector<int> a1(a.begin(), a.begin() + a.size() / 2), a2(a.begin() + a.size() / 2, a.end());
	int c1 = query(x, a1), c2 = query(x, a2);
	if (c1 < a1.size() + 1) find_edges(x, a1);
	if (c2 < a2.size() + 1) find_edges(x, a2);
}
void dfs(int u, int c, vector<vector<int> >& k)
{
	k[c].push_back(u), vis[u] = true;
	for (int v : g[u]) if (!vis[v]) dfs(v, c ^ 1, k);
}
void rmv(int a, int b)
{
	for (int i = 0; i < g[a].size(); i++) if (g[a][i] == b)
	{
		g[a].erase(g[a].begin() + i);
		break;
	}
}
void Solve(int n) 
{
	for (int i = 2; i <= 2 * n; i++)
	{
		vector<vector<int> > k(2);
		fill(vis, vis + maxn, false);
		for (int j = 1; j < i; j++) if (!vis[j]) dfs(j, 0, k);
		find_edges(i, k[0]);
		find_edges(i, k[1]);
	}
	for (int i = 1; i <= 2 * n; i++) if (g[i].size() == 3)
	{
		for (int j = 0; j < 3; j++) for (int k = 0; k < j; k++)
		{
			int c = query(i, { g[i][j], g[i][k] });
			if (c == 1) v.push_back({ i, g[i][3 ^ j ^ k] });
		}
	}
	for (const pair<int, int>& i : v)
	{
		rmv(i.first, i.second);
		rmv(i.second, i.first);
	}
	for (int i = 1; i <= 2 * n; i++) if (g[i][0] > i)
	{
		Answer(i, g[i][0]);
	}
}

Compilation message

chameleon.cpp: In function 'void find_edges(int, const std::vector<int>&)':
chameleon.cpp:26:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  if (c1 < a1.size() + 1) find_edges(x, a1);
      |      ~~~^~~~~~~~~~~~~~~
chameleon.cpp:27:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  if (c2 < a2.size() + 1) find_edges(x, a2);
      |      ~~~^~~~~~~~~~~~~~~
chameleon.cpp: In function 'void rmv(int, int)':
chameleon.cpp:36:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for (int i = 0; i < g[a].size(); i++) if (g[a][i] == b)
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Runtime error 10 ms 536 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 200 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 328 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 2 ms 324 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Runtime error 10 ms 712 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Runtime error 10 ms 536 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -