Submission #486638

#TimeUsernameProblemLanguageResultExecution timeMemory
486638cheissmartMinerals (JOI19_minerals)C++14
85 / 100
45 ms3788 KiB
#include "minerals.h"
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
  cerr << to_string(h);
  if(sizeof ...(t)) cerr << ", ";
  DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 1e9 + 7;

int now;

bool isin(int i) {
	int pre = now;
	now = Query(i);
	return pre == now;
}

void solve(vi a, vi b, int n, bool in) {
	assert(int(a.size()) == n);
	assert(int(b.size()) == n);
	if(n == 1) {
		Answer(a[0], b[0]);	
		return;
	}
	int m = max(1, int(0.382 * n));
	vi al, bl, ar, br;
	for(int i = 0; i < m; i++) {
		now = Query(a[i]);
		al.PB(a[i]);
	}
	for(int i = m; i < n; i++)
		ar.PB(a[i]);
	for(int i:b) {
		if(isin(i)) {
			if(in) br.PB(i);
			else bl.PB(i);
		} else {
			if(in) bl.PB(i);
			else br.PB(i);
		}
	}
	solve(al, bl, m, !in);
	solve(ar, br, n - m, in);
}

void Solve(int n) {
	int pre = 0;
	vi a, b;
	for(int i = 1; i <= 2 * n; i++) {
		now = Query(i);
		if(pre == now)
			a.PB(i);
		else
			b.PB(i);
		pre = now;
	}
	solve(a, b, n, true);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...