답안 #725396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725396 2023-04-17T11:18:26 Z SanguineChameleon 게임 (APIO22_game) C++17
2 / 100
12 ms 14412 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")

#include "game.h"
#include <bits/stdc++.h>
using namespace std;
 
const int maxN = 3e5 + 20;
int block;
int max_in[maxN];
int min_out[maxN];
vector<int> adj1[maxN];
vector<int> adj2[maxN];
bool done = false;
int n, k;

int cnt;

void init(int _n, int _k) {
	n = _n;
	k = _k;
	block = sqrt(k);
	for (int i = 0; i < k; i++) {
		max_in[i] = i - 1;
		min_out[i] = i;
	}
	for (int i = k; i < n; i++) {
		max_in[i] = 0;
		min_out[i] = k - 1;
	}
}

void update_in(int u, int val);

void update_out(int u, int val);

void update_in(int u, int val) {
	if (done) {
		return;
	}
	if (val <= max_in[u]) {
		return;
	}
	cnt++;
	bool update = ((max_in[u] / block) < (val / block) || (max_in[u] / block) == (min_out[u] / block));
	max_in[u] = val;
	if (max_in[u] >= min_out[u]) {
		done = true;
		return;
	}
	if (update) {
		for (auto v: adj1[u]) {
			update_in(v, max_in[u]);
		}
		for (auto v: adj2[u]) {
			update_out(v, min_out[u]);
		}
	}
}
 
void update_out(int u, int val) {
	if (done) {
		return;
	}
	if (val >= min_out[u]) {
		return;
	}
	cnt++;
	bool update = ((min_out[u] / block) > (val / block) || (max_in[u] / block) == (min_out[u] / block));
	min_out[u] = val;
	if (max_in[u] >= min_out[u]) {
		done = true;
		return;
	}
	if (update) {
		for (auto v: adj1[u]) {
			update_in(v, max_in[u]);
		}
		for (auto v: adj2[u]) {
			update_out(v, min_out[u]);
		}
	}
}
 
int add_teleporter(int u, int v) {
	update_in(v, max(max_in[u], (u < k ? u : -1)));
	update_out(u, min_out[v]);
	adj1[u].push_back(v);
	adj2[v].push_back(u);
	return done;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14276 KB Output is correct
2 Correct 10 ms 14316 KB Output is correct
3 Correct 10 ms 14404 KB Output is correct
4 Correct 9 ms 14288 KB Output is correct
5 Correct 12 ms 14412 KB Output is correct
6 Correct 10 ms 14292 KB Output is correct
7 Correct 10 ms 14404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14276 KB Output is correct
2 Correct 10 ms 14316 KB Output is correct
3 Correct 10 ms 14404 KB Output is correct
4 Correct 9 ms 14288 KB Output is correct
5 Correct 12 ms 14412 KB Output is correct
6 Correct 10 ms 14292 KB Output is correct
7 Correct 10 ms 14404 KB Output is correct
8 Incorrect 11 ms 14288 KB Wrong Answer[1]
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14276 KB Output is correct
2 Correct 10 ms 14316 KB Output is correct
3 Correct 10 ms 14404 KB Output is correct
4 Correct 9 ms 14288 KB Output is correct
5 Correct 12 ms 14412 KB Output is correct
6 Correct 10 ms 14292 KB Output is correct
7 Correct 10 ms 14404 KB Output is correct
8 Incorrect 11 ms 14288 KB Wrong Answer[1]
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14276 KB Output is correct
2 Correct 10 ms 14316 KB Output is correct
3 Correct 10 ms 14404 KB Output is correct
4 Correct 9 ms 14288 KB Output is correct
5 Correct 12 ms 14412 KB Output is correct
6 Correct 10 ms 14292 KB Output is correct
7 Correct 10 ms 14404 KB Output is correct
8 Incorrect 11 ms 14288 KB Wrong Answer[1]
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14276 KB Output is correct
2 Correct 10 ms 14316 KB Output is correct
3 Correct 10 ms 14404 KB Output is correct
4 Correct 9 ms 14288 KB Output is correct
5 Correct 12 ms 14412 KB Output is correct
6 Correct 10 ms 14292 KB Output is correct
7 Correct 10 ms 14404 KB Output is correct
8 Incorrect 11 ms 14288 KB Wrong Answer[1]
9 Halted 0 ms 0 KB -