QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#165006#6739. Teleportmendicillin2#WA 26ms17560kbC++172.6kb2023-09-05 15:22:282023-09-05 15:22:28

Judging History

你现在查看的是最新测评结果

  • [2023-09-05 15:22:28]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:17560kb
  • [2023-09-05 15:22:28]
  • 提交

answer

#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;

template <class T> int sz(T&& a) { return int(size(forward<T>(a))); }

template <class T> using vc = vector<T>;
template <class T> using vvc = vc<vc<T>>;

using ll = int64_t;
using vi = vc<int>;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

template <class F>
struct ycr {
	F f;
	template <class T> explicit ycr(T&& f_) : f(forward<T>(f_)) {}

	template <class... Args> decltype(auto) operator()(Args&&... args) {
		return f(ref(*this), forward<Args>(args)...);
	}
};
template <class F> decltype(auto) yc(F&& f) {
	return ycr<decay_t<F>>(forward<F>(f));
}

const int MAXN = 5010;
const int MAXV = MAXN * MAXN;
int par[MAXV];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr);

	const bool debug = false;
	int N, K;
	if (!debug) {
		cin >> N >> K;
	} else {
		N = K = 5000;
	}
	vector<string> grid(N);
	for (int x = 0; x < N; x++) {
		if (!debug) {
			cin >> grid[x];
		} else {
			for (int y = 0; y < N; y++) {
				grid[x] += '.';
			}
		}
	}

	auto getpar = yc([&](auto self, int i) -> int {
		if (par[i] == i) return i;
		return par[i] = self(par[i]);
	});
	auto merge = [&](int x, int y) -> void {
		int i = x * N + y;
		int j = (x+1) * N + (y+1);
		j = getpar(j);
		par[i] = j;
	};

	for (int v = 0; v < N*N; v++) par[v] = v;

	vector<array<int, 2>> bfs; bfs.reserve(N*N);
	vector<vector<int>> dist(N, vector<int>(N, -1));
	auto update = [&](int x, int y, int d) -> void {
		if (x < 0 || x >= N) return;
		if (y < 0 || y >= N) return;
		if (x+1 < N && y+1 < N) {
			merge(x, y);
		}
		if (grid[x][y] == '*') return;
		if (dist[x][y] != -1) return;
		dist[x][y] = d;
		bfs.push_back({x, y});
	};
	update(0, 0, 0);

	auto update_diag = [&](int x_start, int y_start, int s, int d) -> void {
		int x = x_start;
		int y = y_start;
		while (true) {
			int j = getpar(x*N+y);
			x = j / N, y = j % N;
			if (x-x_start >= s) break;
			update(x, y, d);
			if (x+1 >= N || y+1 >= N) break;
			//merge(x, y);
			x++, y++;
		}
	};

	const vector<int> dx = {0, 1, 0, -1};
	const vector<int> dy = {1, 0, -1, 0};
	for (int z = 0; z < int(bfs.size()); z++) {
		auto [x, y] = bfs[z];
		int nd = dist[x][y]+1;
		if (x == N-1 && y == N-1) {
			cout << dist[x][y] << '\n';
			exit(0);
		}
		for (int dir = 0; dir < 4; dir++) {
			int nx = x + dx[dir];
			int ny = y + dy[dir];
			update(nx, ny, nd);
		}
		update_diag(x+1, y+1, K/2, nd);
		update_diag(y+1, x, (K+1)/2, nd);
	}
	//cout << dist[N-1][N-1] << '\n';
	cout << -1 << '\n';
	//cerr << double(clock()) / CLOCKS_PER_SEC << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3664kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3900kb

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 26ms
memory: 17560kb

input:

961 4
...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....

output:

531

result:

wrong answer 1st numbers differ - expected: '540', found: '531'