답안 #602277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602277 2022-07-22T20:23:15 Z patrikpavic2 게임 (APIO22_game) C++17
2 / 100
14 ms 23796 KB
#include "game.h"
#include <vector>
#include <cstdio>
#define PB push_back
 
using namespace std;
 
const int N = 5e5 + 500;
const int BUK = 1;
 
int n, k, ans;
vector < int > v[N], r[N];
int L[N], R[N], bukL[N], bukR[N];
 
void init(int _n, int _k) {
	n = _n, k = _k;
	for(int i = 0;i < n;i++)
		L[i] = -1, R[i] = n, bukL[i] = -1, bukR[i] = n;
	for(int i = 0;i < k;i++)
		L[i] = i, R[i] = i, bukL[i] = i / BUK, bukR[i] = i / BUK;
}
 
void buk_noviL(int x, int vr){
	bukL[x] = vr / BUK;
	for(int y : v[x]) 
		if(bukL[y] < vr / BUK) buk_noviL(y, vr);
}
 
void buk_noviR(int x, int vr){
	bukR[x] = vr / BUK;
	for(int y : r[x])
		if(bukR[y] > vr / BUK) buk_noviR(y, vr);
}
 
void noviL(int x, int vr){
	L[x] = vr;
	for(int y : v[x]) 
		if(L[y] < vr && R[y] / BUK <= vr / BUK) noviL(y, vr);
}
 
void noviR(int x, int vr){
	R[x] = vr;
	for(int y : r[x])
		if(R[y] > vr && L[y] / BUK >= vr / BUK) noviR(y, vr);
}
 
int add_teleporter(int a, int b) {
	v[a].PB(b), r[b].PB(a);
	if(a == b && a < k) ans = 1;
	if(bukL[b] < bukL[a]) buk_noviL(b, L[a]);
	if(bukR[a] > bukR[b]) buk_noviR(a, R[b]);
	ans |= bukL[a] > bukR[a];
	ans |= bukL[b] > bukR[b];
	if(L[b] < L[a] && R[b] / BUK <= L[a] / BUK) noviL(b, L[a]);
	if(R[a] > R[b] && L[a] / BUK >= R[b] / BUK) noviR(a, R[b]);
	if(a >= k) ans |= L[a] == R[a];
	if(b >= k) ans |= L[b] == R[b];
	ans |= L[a] > R[a];
	ans |= L[b] > R[b];
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23772 KB Output is correct
2 Correct 11 ms 23760 KB Output is correct
3 Correct 13 ms 23796 KB Output is correct
4 Correct 14 ms 23760 KB Output is correct
5 Correct 11 ms 23760 KB Output is correct
6 Correct 11 ms 23760 KB Output is correct
7 Correct 12 ms 23760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23772 KB Output is correct
2 Correct 11 ms 23760 KB Output is correct
3 Correct 13 ms 23796 KB Output is correct
4 Correct 14 ms 23760 KB Output is correct
5 Correct 11 ms 23760 KB Output is correct
6 Correct 11 ms 23760 KB Output is correct
7 Correct 12 ms 23760 KB Output is correct
8 Incorrect 11 ms 23760 KB Wrong Answer[1]
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23772 KB Output is correct
2 Correct 11 ms 23760 KB Output is correct
3 Correct 13 ms 23796 KB Output is correct
4 Correct 14 ms 23760 KB Output is correct
5 Correct 11 ms 23760 KB Output is correct
6 Correct 11 ms 23760 KB Output is correct
7 Correct 12 ms 23760 KB Output is correct
8 Incorrect 11 ms 23760 KB Wrong Answer[1]
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23772 KB Output is correct
2 Correct 11 ms 23760 KB Output is correct
3 Correct 13 ms 23796 KB Output is correct
4 Correct 14 ms 23760 KB Output is correct
5 Correct 11 ms 23760 KB Output is correct
6 Correct 11 ms 23760 KB Output is correct
7 Correct 12 ms 23760 KB Output is correct
8 Incorrect 11 ms 23760 KB Wrong Answer[1]
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23772 KB Output is correct
2 Correct 11 ms 23760 KB Output is correct
3 Correct 13 ms 23796 KB Output is correct
4 Correct 14 ms 23760 KB Output is correct
5 Correct 11 ms 23760 KB Output is correct
6 Correct 11 ms 23760 KB Output is correct
7 Correct 12 ms 23760 KB Output is correct
8 Incorrect 11 ms 23760 KB Wrong Answer[1]
9 Halted 0 ms 0 KB -