Submission #116164

# Submission time Handle Problem Language Result Execution time Memory
116164 2019-06-11T04:06:04 Z antimirage Minerals (JOI19_minerals) C++14
0 / 100
5 ms 3712 KB
/**
   I'm sorry...
**/
#include "minerals.h"
//#include "grader.cpp"
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define all(s) s.begin(), s.end()

using namespace std;

int ans[43005][20], u[43005];

void solve (int n){
	
	vector < pair <int, int> > a, b, c, d;
	
	a.pb( {1, n} );
	b.pb( {n + 1, n + n} );
	
	for (int j = 0; j <= 16; j++)
	{
		int last = 0;
		
		for (auto x : a)
		{
			for (int i = x.fr; i <= x.sc; i++){
				int res = Query(i);
				
				if (res == last)
					ans[i][j] = 0;
				
				last = res;
			}
		}
		for (auto x : a)
		{
			for (int i = x.fr; i <= x.sc; i++){
				int res = Query(i);
				
				if (res == last){
					ans[i][j] = 0;
				}
				
				last = res;
			}
		}
		for (auto x : a){
		
			for (int i = x.fr; i <= x.sc; i++){
				if (ans[i][j] == -1)
					ans[i][j] = 1;
			}
		}
		last = 0;
		
		for (auto x : b)
		{
			for (int i = x.fr; i <= x.sc; i++){
				int res = Query(i);
				
				if (res == last)
					ans[i][j] = 1;
				
				last = res;
			}
		}
		for (auto x : b)
		{
			for (int i = x.fr; i <= x.sc; i++){
				int res = Query(i);
				
				if (res == last)
					ans[i][j] = 1;
				
				last = res;
			}
		}
		for (auto x : b){
			
			for (int i = x.fr; i <= x.sc; i++){
				if (ans[i][j] == -1)
					ans[i][j] = 0;
			}
		}
		for (auto x : a){
			if (x.fr == x.sc) continue;
			c.pb( {x.fr, (x.fr + x.sc) / 2} );
			d.pb( {(x.fr + x.sc) / 2 + 1, x.sc} );
		}
		for (auto x : b){
			if (x.fr == x.sc) continue;
			c.pb( {x.fr, (x.fr + x.sc) / 2} );
			d.pb( {(x.fr + x.sc) / 2 + 1, x.sc} );
		}
		a = c;
		b = d;
		c.clear();
		d.clear();
	}
}

int Find (int l, int r, int i, int j)
{
	if (l == r)
		return l;
		
	int md = (l + r) >> 1;
	
	if (ans[i][j] == 0)
		return Find(l, md, i, j + 1);
	else
		return Find(md + 1, r, i, j + 1);
}

void Solve(int n) {

	memset(ans, -1, sizeof(ans) );
	
	solve(n);
	
	for (int i = 1; i <= n + n; i++)
	{
		if (u[i] ) continue;
		
		u[i] = Find(1, n + n, i, 0);
		
		Answer( i, u[i] );
		
		u[ u[i] ] = i;
	}
}
/**
4
1 5
2 6
3 4
7 8
**/
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3712 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3712 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3712 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3712 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3712 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3712 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3712 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3712 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3712 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -