Submission #577642

# Submission time Handle Problem Language Result Execution time Memory
577642 2022-06-15T07:17:08 Z Noam527 Game (APIO22_game) C++17
2 / 100
1 ms 256 KB
#include <bits/stdc++.h>
#include "game.h"
const int OO = 0;
const int OOO = 0;
using namespace std;
 
int n, k;
vector<vector<int>> g, grev;
vector<int> s, e;
// s: maximum that reaches us
// e: minimum that we can reach
// s <= e as long as the answer is 0 (with s < e for all non-special vertices)
 
void init(int nn, int kk) {
	g.clear();
	grev.clear();
	s.clear();
	e.clear();
 
	n = nn;
	k = kk;
	g.resize(n);
	grev.resize(n);
	s.resize(n, -1);
	e.resize(n, n);
 
	for (int i = 0; i < k; i++) {
		s[i] = i;
		e[i] = i;
	}
}
 
void forward_bfs(int l, int m, int r, int v) {
    auto check = [&](int x){
        return l <= e[x] && e[x] <= r && s[x] < m;
    };
    if (!check(v)) return;
	s[v] = m;
	queue<int> q;
	q.push(v);
	while (q.size()) {
		int x = q.front();
		q.pop();
		for (const auto &i : g[x]) {
			if (!check(i)) continue;
			s[i] = m;
			q.push(i);
		}
	}
}
 
void backward_bfs(int l, int m, int r, int v) {
    auto check = [&](int x){
        return m < e[x] && l <= s[v] && s[v] <= r;
    };
	if (!check(v)) return;
	e[v] = m;
	queue<int> q;
	q.push(v);
	while (q.size()) {
		int x = q.front();
		q.pop();
		for (const auto &i : grev[x]) {
			if (!check(i)) continue;
			e[i] = m;
			q.push(i);
		}
	}
}
 
int add(int layer, int l, int r, int u, int v) {
	if (OO) {
		cout << "on layer " << layer << " " << l << " " << r << '\n';
	}
	if (l > r) return 0;
	int m = (l + r) / 2;
	if (s[u] >= e[v]) return 1;
	if (m <= s[u] && s[u] <= r)
		forward_bfs(l, m, r, v);
	if (l <= e[v] && e[v] <= m)
		backward_bfs(l, m, r, u);
 
	if ((m < s[u] && s[u] <= r) || (m < e[v] && e[v] <= r)) {
		if (add(layer + 1, m + 1, r, u, v)) return 1;
	}
	if ((l <= s[u] && s[u] < m) || (l <= e[v] && e[v] < m)) {
		if (add(layer + 1, l, m - 1, u, v)) return 1;
	}
	return 0;
}
 
void brute_dfs(vector<int> &vis, int v) {
	if (vis[v]) return;
	vis[v] = 1;
	for (const auto &i : g[v])
		brute_dfs(vis, i);
}
 
int brute() {
	vector<int> vis(n);
	for (int i = 0; i < k; i++) {
		for (auto &x : vis) x = 0;
		for (const auto &j : g[i])
			brute_dfs(vis, j);
		for (int j = 0; j <= i; j++)
			if (vis[j]) return 1;
	}
	return 0;
}
 
int add_teleporter(int u, int v) {
	if (OO) {
		cout << "current s: ";
		for (const auto &i : s) cout << i << " "; cout << '\n';
		cout << "current e: ";
		for (const auto &i : e) cout << i << " "; cout << '\n';
	}
	
	if (u < k && v < k) {
		return u >= v;
	}
	
	g[u].push_back(v);
	grev[v].push_back(u);
	int x = add(0, 0, k - 1, u, v);
	if (OOO) {
		int y = brute();
		if (x != y) {
			cout << "difference! " << x << " " << y << '\n';
			return 2;
		}
	}
	return x;
}

Compilation message

game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:114:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  114 |   for (const auto &i : s) cout << i << " "; cout << '\n';
      |   ^~~
game.cpp:114:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  114 |   for (const auto &i : s) cout << i << " "; cout << '\n';
      |                                             ^~~~
game.cpp:116:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  116 |   for (const auto &i : e) cout << i << " "; cout << '\n';
      |   ^~~
game.cpp:116:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  116 |   for (const auto &i : e) cout << i << " "; cout << '\n';
      |                                             ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Incorrect 0 ms 208 KB Wrong Answer[1]
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Incorrect 0 ms 208 KB Wrong Answer[1]
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Incorrect 0 ms 208 KB Wrong Answer[1]
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Incorrect 0 ms 208 KB Wrong Answer[1]
9 Halted 0 ms 0 KB -