Submission #112235

# Submission time Handle Problem Language Result Execution time Memory
112235 2019-05-18T01:28:06 Z AngusRitossa Minerals (JOI19_minerals) C++14
100 / 100
73 ms 3068 KB
#include "minerals.h"
#include <bits/stdc++.h>
#include <chrono>
#include <random>

#ifdef DEBUG
	#define D(x...) printf(x)
#else
	#define D(x...)
#endif
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, pre;
vector<int> before, after;
int other[2*70000];
int c;
int doQuery(int a)
{
	c++;
	assert(c != 1.1e6);
	D("querying %d\n", a);
	return Query(a);
}
void solve(vector<int> &b, vector<int> &a, bool inv = 0, bool shouldrem = 1, int half = -1)
{
	D("\n%lu %lu inv %d\n", a.size(), b.size(), inv);
	for (auto i : b) D("%d ", i);
	D(" a\n");
	for (auto i : a) D("%d ", i);
	D(" b\n");
	assert(a.size() == b.size());
	if (b.size() == 1)
	{
		other[a[0]] = b[0];
		return;
	}
	vector<int> firsthalf, secondhalf;
	vector<int> fa, sa;
	int ignore = 1e9;
	if (half < 0) ignore = ((int)b.size()) + half+1;
	if (half < 0)
	{
		half = b.size()/2;
		if (shouldrem) half += b.size()/10;
	}
	for (int i = 0; i < b.size(); i++)
	{
		if (i < half) 
		{
			firsthalf.push_back(b[i]);
			if (i >= ignore) pre = doQuery(b[i]);
		}
		else 
		{
			secondhalf.push_back(b[i]);
			if (shouldrem && i < ignore) pre = doQuery(b[i]);
			else if (shouldrem) D("ignored %d\n", b[i]);
		}
	}
	if (inv) swap(firsthalf, secondhalf);
	int oldpre = pre;
	int sta = 0;
	shuffle(a.begin(), a.end(), rng);
	for (auto i : a)
	{
		if (fa.size() == b.size()-1) { sa.push_back(i); continue; }
		if (sa.size() == b.size()-1) { fa.push_back(i); continue; }
		if (fa.size() == firsthalf.size() && pre < oldpre)
		{
			sa.insert(sa.begin(), i); sta++;
			continue;
		}
		else if (sa.size() == secondhalf.size())
		{
			sta--;
			fa.push_back(i);
		//	D("doing this! %d\n", i);
			continue;
		}
		int q = doQuery(i);
		if (q == pre)
		{
			fa.push_back(i);
		}
		else
		{
			sa.push_back(i);
		}
		pre = q;
	}
	int h = -1;
	if (sta < 0) h = sta-1;
	if (h == -1) solve(firsthalf, fa, 0, 1, h);
	else solve(fa, firsthalf, pre < oldpre, 1, h);
	if (pre >= oldpre) 
	{ 
		solve(sa, secondhalf, 0);
	}
	else
	{
		sta = max(sta, 0);
		int half = sa.size()/2;
		half -= sa.size()/10;
		if (sta-1 >= half) half += sa.size()/10;
		while (sta-1 >= half)
		{
			pre = doQuery(sa[--sta]);
		}
		for (int i = sta; i < half; i++) pre = doQuery(sa[i]);
		solve(sa, secondhalf, 0, 0, half);
	}
}
void Solve(int N) 
{
	n = N;
	for (int i = 1; i <= 2*n; i++)
	{
		int q = doQuery(i);
		if (q != pre) before.push_back(i);
		else after.push_back(i);
		pre = q;
	}
	solve(before, after);
	for (int i = 1; i <= 2*n; i++)
	{
		if (other[i]) 
		{
			Answer(i, other[i]);
		}
	}
}

Compilation message

minerals.cpp: In function 'void solve(std::vector<int>&, std::vector<int>&, bool, bool, int)':
minerals.cpp:27:12: warning: unused variable 'i' [-Wunused-variable]
  for (auto i : b) D("%d ", i);
            ^
minerals.cpp:29:12: warning: unused variable 'i' [-Wunused-variable]
  for (auto i : a) D("%d ", i);
            ^
minerals.cpp:46:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < b.size(); i++)
                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 300 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 12 ms 828 KB Output is correct
5 Correct 21 ms 1220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 300 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 12 ms 828 KB Output is correct
9 Correct 21 ms 1220 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 15 ms 1072 KB Output is correct
12 Correct 22 ms 1408 KB Output is correct
13 Correct 21 ms 1280 KB Output is correct
14 Correct 23 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 300 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 12 ms 828 KB Output is correct
9 Correct 21 ms 1220 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 15 ms 1072 KB Output is correct
12 Correct 22 ms 1408 KB Output is correct
13 Correct 21 ms 1280 KB Output is correct
14 Correct 23 ms 1152 KB Output is correct
15 Correct 59 ms 2676 KB Output is correct
16 Correct 61 ms 2684 KB Output is correct
17 Correct 57 ms 2592 KB Output is correct
18 Correct 56 ms 2496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 300 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 12 ms 828 KB Output is correct
9 Correct 21 ms 1220 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 15 ms 1072 KB Output is correct
12 Correct 22 ms 1408 KB Output is correct
13 Correct 21 ms 1280 KB Output is correct
14 Correct 23 ms 1152 KB Output is correct
15 Correct 59 ms 2676 KB Output is correct
16 Correct 61 ms 2684 KB Output is correct
17 Correct 57 ms 2592 KB Output is correct
18 Correct 56 ms 2496 KB Output is correct
19 Correct 62 ms 2804 KB Output is correct
20 Correct 64 ms 2804 KB Output is correct
21 Correct 57 ms 2744 KB Output is correct
22 Correct 56 ms 2596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 300 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 12 ms 828 KB Output is correct
9 Correct 21 ms 1220 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 15 ms 1072 KB Output is correct
12 Correct 22 ms 1408 KB Output is correct
13 Correct 21 ms 1280 KB Output is correct
14 Correct 23 ms 1152 KB Output is correct
15 Correct 59 ms 2676 KB Output is correct
16 Correct 61 ms 2684 KB Output is correct
17 Correct 57 ms 2592 KB Output is correct
18 Correct 56 ms 2496 KB Output is correct
19 Correct 62 ms 2804 KB Output is correct
20 Correct 64 ms 2804 KB Output is correct
21 Correct 57 ms 2744 KB Output is correct
22 Correct 56 ms 2596 KB Output is correct
23 Correct 65 ms 2824 KB Output is correct
24 Correct 66 ms 2860 KB Output is correct
25 Correct 61 ms 2680 KB Output is correct
26 Correct 59 ms 2548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 300 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 12 ms 828 KB Output is correct
9 Correct 21 ms 1220 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 15 ms 1072 KB Output is correct
12 Correct 22 ms 1408 KB Output is correct
13 Correct 21 ms 1280 KB Output is correct
14 Correct 23 ms 1152 KB Output is correct
15 Correct 59 ms 2676 KB Output is correct
16 Correct 61 ms 2684 KB Output is correct
17 Correct 57 ms 2592 KB Output is correct
18 Correct 56 ms 2496 KB Output is correct
19 Correct 62 ms 2804 KB Output is correct
20 Correct 64 ms 2804 KB Output is correct
21 Correct 57 ms 2744 KB Output is correct
22 Correct 56 ms 2596 KB Output is correct
23 Correct 65 ms 2824 KB Output is correct
24 Correct 66 ms 2860 KB Output is correct
25 Correct 61 ms 2680 KB Output is correct
26 Correct 59 ms 2548 KB Output is correct
27 Correct 66 ms 2932 KB Output is correct
28 Correct 68 ms 2932 KB Output is correct
29 Correct 65 ms 2748 KB Output is correct
30 Correct 64 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 300 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 12 ms 828 KB Output is correct
9 Correct 21 ms 1220 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 15 ms 1072 KB Output is correct
12 Correct 22 ms 1408 KB Output is correct
13 Correct 21 ms 1280 KB Output is correct
14 Correct 23 ms 1152 KB Output is correct
15 Correct 59 ms 2676 KB Output is correct
16 Correct 61 ms 2684 KB Output is correct
17 Correct 57 ms 2592 KB Output is correct
18 Correct 56 ms 2496 KB Output is correct
19 Correct 62 ms 2804 KB Output is correct
20 Correct 64 ms 2804 KB Output is correct
21 Correct 57 ms 2744 KB Output is correct
22 Correct 56 ms 2596 KB Output is correct
23 Correct 65 ms 2824 KB Output is correct
24 Correct 66 ms 2860 KB Output is correct
25 Correct 61 ms 2680 KB Output is correct
26 Correct 59 ms 2548 KB Output is correct
27 Correct 66 ms 2932 KB Output is correct
28 Correct 68 ms 2932 KB Output is correct
29 Correct 65 ms 2748 KB Output is correct
30 Correct 64 ms 2636 KB Output is correct
31 Correct 68 ms 2960 KB Output is correct
32 Correct 73 ms 3068 KB Output is correct
33 Correct 67 ms 2828 KB Output is correct
34 Correct 68 ms 2756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 300 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 12 ms 828 KB Output is correct
9 Correct 21 ms 1220 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 15 ms 1072 KB Output is correct
12 Correct 22 ms 1408 KB Output is correct
13 Correct 21 ms 1280 KB Output is correct
14 Correct 23 ms 1152 KB Output is correct
15 Correct 59 ms 2676 KB Output is correct
16 Correct 61 ms 2684 KB Output is correct
17 Correct 57 ms 2592 KB Output is correct
18 Correct 56 ms 2496 KB Output is correct
19 Correct 62 ms 2804 KB Output is correct
20 Correct 64 ms 2804 KB Output is correct
21 Correct 57 ms 2744 KB Output is correct
22 Correct 56 ms 2596 KB Output is correct
23 Correct 65 ms 2824 KB Output is correct
24 Correct 66 ms 2860 KB Output is correct
25 Correct 61 ms 2680 KB Output is correct
26 Correct 59 ms 2548 KB Output is correct
27 Correct 66 ms 2932 KB Output is correct
28 Correct 68 ms 2932 KB Output is correct
29 Correct 65 ms 2748 KB Output is correct
30 Correct 64 ms 2636 KB Output is correct
31 Correct 68 ms 2960 KB Output is correct
32 Correct 73 ms 3068 KB Output is correct
33 Correct 67 ms 2828 KB Output is correct
34 Correct 68 ms 2756 KB Output is correct
35 Correct 69 ms 2916 KB Output is correct
36 Correct 72 ms 3060 KB Output is correct
37 Correct 71 ms 2868 KB Output is correct
38 Correct 66 ms 2584 KB Output is correct