QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#706382#3514. BoulderingJay202WA 12ms50248kbC++172.1kb2024-11-03 10:59:392024-11-03 10:59:40

Judging History

This is the latest submission verdict.

  • [2024-11-03 10:59:40]
  • Judged
  • Verdict: WA
  • Time: 12ms
  • Memory: 50248kb
  • [2024-11-03 10:59:39]
  • Submitted

answer

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <cassert>

const int LEN = 101;
const int N_LEN = 1001;
const int M_LEN = 10001;
const int INF = 1e9 + 7;
const double EPS = 1e-7;

struct E {
	int u, c;
	double d;
	bool operator<(const E& r) const {
		return abs(d - r.d) < EPS ? c > r.c : d > r.d;
	}
};

int H, W, R, S, N, M;
double dp[N_LEN][M_LEN];
char map[LEN][LEN];
int x[N_LEN], y[N_LEN], dif[N_LEN];

std::vector<E> graph[N_LEN];
std::priority_queue<E> pq;

int main() {
	std::cin.tie(0)->sync_with_stdio(0);
	std::cin >> H >> W >> R >> S;
	for (int i = 0; i < H; ++i) {
		std::cin >> map[i];
		for (int j = 0; j < W; ++j) {
			if (map[i][j] != '.') {
				N++;
				x[N] = i; y[N] = j; dif[N] = map[i][j] - '0';
			}
		}
	}
	M = std::min(N * 9, S);
	assert(M <= 6260);

	for (int i = 1; i <= N; ++i)
		for (int j = 0; j <= M; ++j) 
			dp[i][j] = INF;

	for (int u = 1; u <= N; ++u) {
		for (int v = 1; v <= N; ++v) {
			if (u == v) continue;
			int dx = x[u] - x[v];
			int dy = y[u] - y[v];
			if (dx * dx + dy * dy <= R * R) {
				graph[u].push_back({ v, dif[v], sqrt(dx * dx + dy * dy) });
			}
		}
	}
	for (int i = 1; i <= N; ++i) std::sort(graph[i].begin(), graph[i].end());
	for (int i = 0; i <= M; ++i) dp[N][i] = 0;
	pq.push({ N, 0, 0 });
	while (pq.size()) {
		int u = pq.top().u;
		int m = pq.top().c;
		double dist = pq.top().d;
		 pq.pop();
		
		 if (u == 1) continue;
		if (dist > dp[u][m]) continue;
		for (int i = graph[u].size() - 1; i >= 0; --i) {
			const E& e = graph[u][i];
			int v = e.u, c = m + e.c;
			double d = dist + e.d;
			if (c > M) continue;
			if (dp[v][c] > d) {
				dp[v][c] = d;
				for (int k = c + 1; k <= M; ++k) {
					if (dp[v][k] < d) break;
					dp[v][k] = d;
				}
				pq.push({ v, c, d });
			}
		}
	}
	double result = INF;
	for (int c = 0; c <= M; ++c)
		if (dp[1][c] < result)
			result = dp[1][c];

	std::cout << std::fixed;
	std::cout.precision(9);
	if (result > INF - 1) std::cout << "impossible";
	else std::cout << result;
}

詳細信息

Test #1:

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

input:

12 11 3 11
...........
........3..
.......3.1.
...........
.......2...
.....2.....
.1.1.......
.....2.....
.1.........
...2.......
.1.........
...........

output:

13.543203767

result:

ok 

Test #2:

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

input:

8 16 3 15
......1.........
....1..1.1......
..2........1....
...2......1.....
.....4.1..2..1..
................
.......1........
................

output:

6.414213562

result:

ok 

Test #3:

score: 0
Accepted
time: 1ms
memory: 5800kb

input:

10 10 2 10
...2......
..........
...5.2....
..........
.....3....
....5.....
..2....2..
..1.......
....2.....
..1.......

output:

impossible

result:

ok 

Test #4:

score: 0
Accepted
time: 1ms
memory: 6104kb

input:

5 5 1 100
....1
.1111
.1.9.
.119.
..1..

output:

6.000000000

result:

ok 

Test #5:

score: 0
Accepted
time: 1ms
memory: 6012kb

input:

6 7 3 10
..6....
..1....
.......
.5..1..
.......
..1....

output:

6.656854249

result:

ok 

Test #6:

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

input:

2 18 2 5
.............1....
...............9..

output:

impossible

result:

ok 

Test #7:

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

input:

25 25 1 1000000
9........................
21.21921.21921.21921.2193
92.92.92.92.92.92.92.92.3
.2..2..2..2..2..2..2..2.3
12.12.12.12.12.12.12.12.3
29.29.29.29.29.29.29.29.3
2..2..2..2..2..2..2..2..3
21.21.21.21.21.21.21.21.3
92.92.92.92.92.92.92.92.3
.2..2..2..2..2..2..2..2.3
12.12.12.12.12.12.12.12....

output:

272.000000000

result:

ok 

Test #8:

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

input:

2 18 2 5
.............9....
...............1..

output:

impossible

result:

ok 

Test #9:

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

input:

3 3 2 7
..3
...
..4

output:

2.000000000

result:

ok 

Test #10:

score: 0
Accepted
time: 3ms
memory: 49288kb

input:

25 25 1 1000000000
........................1
2547174745232875997886554
7965651126962942737771266
6728739299224693912515356
3892629154668465958161356
7224952531945412299918567
6652628797132321234345444
2166938247278479435464195
4614671371217599224792557
1652832422769863877435862
528832887161666938898...

output:

48.000000000

result:

ok 

Test #11:

score: 0
Accepted
time: 10ms
memory: 49608kb

input:

25 25 3 1000000000
........................1
9726394797162243248412114
2389413121411497892345775
3536731263389491377529168
8539547197629558379487557
3476316664681454144237253
7167793883245166544976269
6551392597242556216495516
2913226341422851312188434
4794887856899463978185497
183788127159254461697...

output:

33.941125497

result:

ok 

Test #12:

score: 0
Accepted
time: 8ms
memory: 50248kb

input:

25 25 3 100000
........................1
9726394797162243248412114
2389413121411497892345775
3536731263389491377529168
8539547197629558379487557
3476316664681454144237253
7167793883245166544976269
6551392597242556216495516
2913226341422851312188434
4794887856899463978185497
1837881271592544616972778...

output:

33.941125497

result:

ok 

Test #13:

score: 0
Accepted
time: 12ms
memory: 50212kb

input:

25 25 3 1000000000
........................1
2547174745232875997886554
7965651126962942737771266
6728739299224693912515356
3892629154668465958161356
7224952531945412299918567
6652628797132321234345444
2166938247278479435464195
4614671371217599224792557
1652832422769863877435862
528832887161666938898...

output:

33.941125497

result:

ok 

Test #14:

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

input:

25 25 1 1000000000
........................1
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
111111111111111111111...

output:

48.000000000

result:

ok 

Test #15:

score: 0
Accepted
time: 12ms
memory: 49908kb

input:

25 25 3 1000000000
........................1
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
1111111111111111111111111
111111111111111111111...

output:

33.941125497

result:

ok 

Test #16:

score: 0
Accepted
time: 1ms
memory: 10116kb

input:

10 10 1 1000000000
.........1
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1.........

output:

18.000000000

result:

ok 

Test #17:

score: 0
Accepted
time: 1ms
memory: 8160kb

input:

18 20 3 549
...................9
.9.9.9.9.9.9.9.9.9..
....................
9...................
9.9.9.9.9.9.9.9.9.9.
....................
...................9
.9.9.9.9.9.9.9.9.9.9
....................
9...................
9.9.9.9.9.9.9.9.9.9.
....................
...................9
.9.9.9.9.9.9.9....

output:

122.010961315

result:

ok 

Test #18:

score: -100
Wrong Answer
time: 0ms
memory: 20476kb

input:

18 20 3 227
...................9
.9.9.9.9.9.9.9.9.9..
....................
9...................
9.9.9.9.9.9.9.9.9.9.
....................
...................9
.1.1...............9
99999999999999991991
19991999999991999999
99999999999999999999
19991999999999199999
99999999999999999999
199999199999999...

output:

68.652475842

result:

wrong answer