Submission #550751

# Submission time Handle Problem Language Result Execution time Memory
550751 2022-04-19T01:59:08 Z 8e7 Chameleon's Love (JOI20_chameleon) C++17
100 / 100
70 ms 1412 KB
//Challenge: Accepted
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "chameleon.h"
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 1005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
namespace {
	vector<int> ord, adj[maxn];
	bool vis[maxn];
	bool bad[maxn][maxn];
	void dfs(int n, int c, vector<int> &lef, vector<int> &rig) {
		vis[n] = 1;
		if (c) rig.push_back(n);
		else lef.push_back(n);
		for (int v:adj[n]) {
			if (!vis[v]) dfs(v, 1 - c, lef, rig); 
		}
	}
	int query(int x, vector<int> &v, int l, int r) { //[l, r)
		//debug(x, l, r);
		vector<int> vec;
		vec.push_back(ord[x]);
		for (int i = l;i < r;i++) vec.push_back(ord[v[i]]);
		if (r - l == 0) return 1;
		else return r - l + 1 - Query(vec);
	}
	void addedge(int x, vector<int> &v, int l) {
		if (l >= v.size() || !query(x, v, l, v.size())) return;
		int low = l, up = v.size();	
		while (low < up - 1) {
			int mid = (low + up) / 2;
			if (query(x, v, low, mid)) up = mid;
			else low = mid;
		}
		adj[x].push_back(v[low]);
		adj[v[low]].push_back(x);
		debug("edge", x, v[low]);
		addedge(x, v, low + 1);	
	}
}
void Solve(int N) {
	srand(time(NULL));
	vector<int> lef, rig;
	for (int i = 1;i <= 2 * N;i++) ord.push_back(i);	
	//random_shuffle(ord.begin(), ord.end());	
	ord.insert(ord.begin(), 0);
	//pary(ord.begin(), ord.end());
	for (int i = 2 * N;i > 0;i--) {
		random_shuffle(lef.begin(), lef.end());
		random_shuffle(rig.begin(), rig.end());
		addedge(i, lef, 0);
		addedge(i, rig, 0);
		for (int j = i;j <= 2 * N;j++) vis[j] = 0;		
		lef.clear(), rig.clear();
		for (int j = i;j <= 2 * N;j++) {
			if (!vis[j]) dfs(j, rand() % 2, lef, rig);
		}
		pary(lef.begin(), lef.end());
		pary(rig.begin(), rig.end());
		debug();
	}
	debug();
	auto getbad = [&](vector<int> &vec) {
		for (int i:vec) {
			if (adj[i].size() == 3) {
				vector<int> t1(1, ord[i]), t2(1, ord[i]);
				t1.push_back(ord[adj[i][0]]);
				t1.push_back(ord[adj[i][2]]);
				t2.push_back(ord[adj[i][0]]);
				t2.push_back(ord[adj[i][1]]);

				pary(t1.begin(), t1.end());
				pary(t2.begin(), t2.end());
				int val = 0;
				if (Query(t1) == 1) val = 1;
				else if (Query(t2) == 1) val = 2;
				bad[i][adj[i][val]] = bad[adj[i][val]][i] = 1;	
			}
		}
	};
	getbad(lef), getbad(rig);
	for (int i:lef) {
		debug(i);
		if (adj[i].size() == 1) debug(ord[i], ord[adj[i][0]]), Answer(ord[i], ord[adj[i][0]]);
		else {
			for (int v:adj[i]) {
				if (!bad[i][v]) debug(ord[i], ord[adj[i][0]]), Answer(ord[i], ord[v]);
			}
		}
	}
}

Compilation message

chameleon.cpp: In function 'void {anonymous}::addedge(int, std::vector<int>&, int)':
chameleon.cpp:44:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   if (l >= v.size() || !query(x, v, l, v.size())) return;
      |       ~~^~~~~~~~~~~
chameleon.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 0
      |                    ^
chameleon.cpp:53:3: note: in expansion of macro 'debug'
   53 |   debug("edge", x, v[low]);
      |   ^~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:15:19: warning: statement has no effect [-Wunused-value]
   15 | #define pary(...) 0
      |                   ^
chameleon.cpp:74:3: note: in expansion of macro 'pary'
   74 |   pary(lef.begin(), lef.end());
      |   ^~~~
chameleon.cpp:15:19: warning: statement has no effect [-Wunused-value]
   15 | #define pary(...) 0
      |                   ^
chameleon.cpp:75:3: note: in expansion of macro 'pary'
   75 |   pary(rig.begin(), rig.end());
      |   ^~~~
chameleon.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 0
      |                    ^
chameleon.cpp:76:3: note: in expansion of macro 'debug'
   76 |   debug();
      |   ^~~~~
chameleon.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 0
      |                    ^
chameleon.cpp:78:2: note: in expansion of macro 'debug'
   78 |  debug();
      |  ^~~~~
chameleon.cpp: In lambda function:
chameleon.cpp:15:19: warning: statement has no effect [-Wunused-value]
   15 | #define pary(...) 0
      |                   ^
chameleon.cpp:88:5: note: in expansion of macro 'pary'
   88 |     pary(t1.begin(), t1.end());
      |     ^~~~
chameleon.cpp:15:19: warning: statement has no effect [-Wunused-value]
   15 | #define pary(...) 0
      |                   ^
chameleon.cpp:89:5: note: in expansion of macro 'pary'
   89 |     pary(t2.begin(), t2.end());
      |     ^~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 0
      |                    ^
chameleon.cpp:99:3: note: in expansion of macro 'debug'
   99 |   debug(i);
      |   ^~~~~
chameleon.cpp:14:20: warning: left operand of comma operator has no effect [-Wunused-value]
   14 | #define debug(...) 0
      |                    ^
chameleon.cpp:100:27: note: in expansion of macro 'debug'
  100 |   if (adj[i].size() == 1) debug(ord[i], ord[adj[i][0]]), Answer(ord[i], ord[adj[i][0]]);
      |                           ^~~~~
chameleon.cpp:14:20: warning: left operand of comma operator has no effect [-Wunused-value]
   14 | #define debug(...) 0
      |                    ^
chameleon.cpp:103:21: note: in expansion of macro 'debug'
  103 |     if (!bad[i][v]) debug(ord[i], ord[adj[i][0]]), Answer(ord[i], ord[v]);
      |                     ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 42 ms 380 KB Output is correct
4 Correct 42 ms 336 KB Output is correct
5 Correct 43 ms 392 KB Output is correct
6 Correct 42 ms 464 KB Output is correct
7 Correct 43 ms 468 KB Output is correct
8 Correct 43 ms 364 KB Output is correct
9 Correct 45 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 58 ms 1300 KB Output is correct
4 Correct 65 ms 1400 KB Output is correct
5 Correct 63 ms 1284 KB Output is correct
6 Correct 59 ms 1288 KB Output is correct
7 Correct 61 ms 1320 KB Output is correct
8 Correct 58 ms 1292 KB Output is correct
9 Correct 61 ms 1352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 42 ms 380 KB Output is correct
4 Correct 42 ms 336 KB Output is correct
5 Correct 43 ms 392 KB Output is correct
6 Correct 42 ms 464 KB Output is correct
7 Correct 43 ms 468 KB Output is correct
8 Correct 43 ms 364 KB Output is correct
9 Correct 45 ms 500 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 0 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 58 ms 1300 KB Output is correct
31 Correct 65 ms 1400 KB Output is correct
32 Correct 63 ms 1284 KB Output is correct
33 Correct 59 ms 1288 KB Output is correct
34 Correct 61 ms 1320 KB Output is correct
35 Correct 58 ms 1292 KB Output is correct
36 Correct 61 ms 1352 KB Output is correct
37 Correct 61 ms 1308 KB Output is correct
38 Correct 43 ms 336 KB Output is correct
39 Correct 63 ms 1304 KB Output is correct
40 Correct 59 ms 1320 KB Output is correct
41 Correct 62 ms 1412 KB Output is correct
42 Correct 43 ms 364 KB Output is correct
43 Correct 66 ms 1288 KB Output is correct
44 Correct 70 ms 1300 KB Output is correct
45 Correct 60 ms 1352 KB Output is correct