제출 #1363371

#제출 시각아이디문제언어결과실행 시간메모리
1363371MateiKing80Voltage 2 (JOI26_voltage)C++20
100 / 100
46 ms980 KiB
#include <bits/stdc++.h>
#include "voltage.h"

using namespace std;

const int N = 505;
vector<int> in[N], out[N];

bool solve(int n, int m) {
	vector<int> gol, full0(n, 0);
	
	auto adaugabil = [&] (int p) -> bool {
		vector<int> x(n, 1);
		for (auto i : in[p]) {
			x[i] = 0;
		}
		auto y = x;
		x[p] = 0;
		y[p] = 1;
		return query(x, y) == 0;
	};
	
	for (int i = 0; i < n; i ++) {
		if (adaugabil(i)) {
			//~ cout << i << '\n';
			gol.push_back(i);
		}
	}
	
	vector<bool> skib(n);
	
	int nrq = 0;
	
	while (!gol.empty()) {
		auto p = gol.back();
		gol.pop_back();
		
		//~ cout << p << '\n';
		
		if (skib[p]) {
			return false;
		}
		skib[p] = true;
		
		// mi se garanteaza ca stiu deja toate muchiile de intrare la x
		// vreau sa ii vad muchiile de iesire
		
		while (1) {
			int pos = -1;
			for (int pas = 1 << 10; pas; pas >>= 1) {
				if (pos + pas > n) {
					continue;
				}
				// vreau sa vad daca omul meu x are muchie cu cel putin un nod pana in pos
				vector<int> x(n, 0);
				for (int j = pos + pas; j < n; j ++) {
					x[j] = 1;
				}
				for (auto j : in[p]) {
					x[j] = 0;
				}
				for (auto j : out[p]) {
					x[j] = 1;
				}
				auto y = x;
				x[p] = 0;
				y[p] = 1;
				if (query(x, y) == 0) {
					pos += pas;
				}
			}
			if (pos == n) {
				break;
			}
			
			nrq ++;
			
			if (nrq > m) {
				return false;
			}
			
			//~ cerr << p << " " << pos << '\n';
			
			in[pos].push_back(p);
			out[p].push_back(pos);
			
			if (adaugabil(pos)) {
				gol.push_back(pos);
			}
		}
	}
	
	for (int i = 0; i < n; i ++) {
		if (skib[i] == false) {
			return false;
		}
	}
	
	for (int i = 0; i < n; i ++) {
		for (auto j : out[i]) {
			answer(i, j);
		}
	}
	return true;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…