QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722213#3514. Boulderingcrimson231AC ✓11ms42468kbC++233.5kb2024-11-07 18:11:402024-11-07 18:11:40

Judging History

This is the latest submission verdict.

  • [2024-11-07 18:11:40]
  • Judged
  • Verdict: AC
  • Time: 11ms
  • Memory: 42468kb
  • [2024-11-07 18:11:40]
  • Submitted

answer

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <vector>
#include <queue>
typedef long long ll;
//typedef long double ld;
typedef double ld;
typedef std::vector<int> Vint;
typedef std::vector<ld> Vld;
const ll INF = 1e17;
const int LEN = 101;
const ld TOL = 1e-7;
inline int sign(const ld& x) { return x < -TOL ? -1 : x > TOL; }
inline bool zero(const ld& x) { return !sign(x); }
inline bool eq(const ld& u, const ld& v) { return zero(u - v); }
inline int sq(const int& x) { return x * x; }

int N, M, H, W, R, S;
char B[LEN][LEN];
struct Pos {
	int x, y;
	int c;
	Pos(int X = 0, int Y = 0, int C = 0) : x(X), y(Y), c(C) {}
	Pos operator + (const Pos& p) const { return { x + p.x, y + p.y }; }
	Pos operator - (const Pos& p) const { return { x - p.x, y - p.y }; }
	int Euc() const { return sq(x) + sq(y); }
	ld mag() const { return hypot(x, y); }
	friend std::istream& operator >> (std::istream& is, Pos& p) { is >> p.x >> p.y; return is; }
	friend std::ostream& operator << (std::ostream& os, const Pos& p) { os << p.x << " " << p.y; return os; }
}; const Pos O = Pos(0, 0);
typedef std::vector<Pos> Polygon;
struct Info {
	int i, c;
	ld d;
	Info(int i_ = 0, int c_ = 0, ld d_ = 0) : i(i_), c(c_), d(d_) {}
	bool operator < (const Info& w) const { return eq(d, w.d) ? c > w.c : d > w.d; }
};
std::vector<Info> G[1 << 10];
std::priority_queue<Info> Q;
ld C[1 << 10][1 << 13];
void dijkstra(const int& s, const Pos& v) {
	Q.push(Info(s, v.c, 0));
	while (!Q.empty()) {
		Info p = Q.top(); Q.pop();
		if (p.i == 0) continue;//도착하면 더 이상 갈 필요 없음
		if (p.d > C[p.i][p.c]) continue;//거리가 더 커도 갈 필요 없음
		for (const Info& w : G[p.i]) {
			int c = p.c + w.c;
			ld d = p.d + w.d;
			if (c > M) continue;//carl의 체력이 고갈
			if (C[w.i][c] > d) {//해당 체력으로 도착했을 때 더 짧은 거리로 이동할 수 있을 경우
				C[w.i][c] = d;//거리를 갱신
				for (int j = c + 1; j <= M; j++) {//보다 더 체력을 소모할 때
					if (C[w.i][j] < d) break;//소비한 스테미너가 더 많은데 거리는 짧을 때 break
					C[w.i][j] = d;//거리를 갱신
				}
				Q.push(Info(w.i, c, d));
			}
		}
	}
	return;
}
void solve() {
	std::cin.tie(0)->sync_with_stdio(0);
	std::cout.tie(0);
	std::cout << std::fixed;
	std::cout.precision(9);
	std::cin >> H >> W >> R >> S;
	R = sq(R);
	Polygon P;
	for (int i = 0; i < H; i++) {
		std::cin >> B[i];
		for (int j = 0; j < W; j++) {
			if (B[i][j] != '.') P.push_back(Pos(i, j, B[i][j] - '0'));//정점 수집
		}
	}
	N = P.size();
	M = std::min(N * 9, S);
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			const Pos& p = P[i], & q = P[j];
			int D = (p - q).Euc();
			if (D <= R) {
				ld d = (p - q).mag();
				G[i].push_back(Info(j, q.c, d));//그래프 구성
				G[j].push_back(Info(i, p.c, d));//그래프 구성
			}
		}
	}
	for (int i = 0; i < N; i++)
		for (int j = 0; j <= M; j++)
			C[i][j] = INF;//비용 초기화
	//for (int j = 0; j <= M; j++) C[N - 1][j] = P[N - 1].c;//이건 뭘까?
	for (int j = 0; j <= M; j++) C[N - 1][j] = 0;//이건 뭘까?
	for (int i = 0; i < N; i++) std::sort(G[i].rbegin(), G[i].rend());//정렬을 왜 하지?
	dijkstra(N - 1, P[N - 1]);
	ld ret = INF;
	for (int j = 0; j <= M; j++) ret = std::min(ret, C[0][j]);
	if (ret > 1e16) std::cout << "impossible\n";
	else std::cout << ret << "\n";
	return;
}
int main() { solve(); return 0; }//boj18055

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 5960kb

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: 3728kb

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: 6016kb

input:

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

output:

6.000000000

result:

ok 

Test #5:

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

input:

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

output:

6.656854249

result:

ok 

Test #6:

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

input:

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

output:

impossible

result:

ok 

Test #7:

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

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: 3636kb

input:

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

output:

impossible

result:

ok 

Test #9:

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

input:

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

output:

2.000000000

result:

ok 

Test #10:

score: 0
Accepted
time: 4ms
memory: 40892kb

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: 11ms
memory: 42220kb

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: 9ms
memory: 42028kb

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: 3ms
memory: 42468kb

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: 4ms
memory: 40920kb

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: 5ms
memory: 41976kb

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: 0ms
memory: 12140kb

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: 0ms
memory: 8072kb

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: 0
Accepted
time: 2ms
memory: 16360kb

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:

83.367252485

result:

ok 

Test #19:

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

input:

25 25 3 1000000000
.......................9.
9999999999999999999999999
9999999999999999999999999
9999999999999999999999999
9999999999999999999999999
9999999999999999999999999
9999999999999999999999999
9999999999999999999999999
9999999999999999999999999
9999999999999999999999999
999999999999999999999...

output:

33.348766350

result:

ok 

Test #20:

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

input:

2 1 1 2
1
1

output:

1.000000000

result:

ok 

Test #21:

score: 0
Accepted
time: 2ms
memory: 11976kb

input:

25 25 2 242
3........................
..71............8.......3
8..7..9....96..4.8...6...
........2...87.1.........
...26.........65396...182
..16....2.4..5....8971...
.....7.8..6...6.7..1..5..
...........914...4...4...
....51..4.....22......6..
6..........8..53.41...4..
.5.4........4...1......82
.....

output:

impossible

result:

ok 

Test #22:

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

input:

25 25 2 273
......9..................
.9..8........2.5.59...962
........5..7....4....7..8
.87....7...2..........4..
....2....5...........87..
81...29..697.......9.483.
448.....1.....46....31...
.3..4.......3....6.......
..4.....7..............6.
...4....4....1..3........
...3..4.13..4..2.2.95..4.
3....

output:

impossible

result:

ok 

Test #23:

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

input:

25 25 3 194
.7.......................
.9.......7...9...........
99.....5.....2..84..3....
.8....9...76..6..6.9..6..
...3..4....6....22.1.....
.2....95...3..4.2.41.....
...7.3..5.46..9..7..25...
2....21....2..83..1....31
94......9.4..............
8........2.1.8.........9.
...68.3.5.9..5...........
9....

output:

35.157475346

result:

ok 

Test #24:

score: 0
Accepted
time: 2ms
memory: 13972kb

input:

25 25 3 437
5........................
6.6.....6...6..84......5.
2....6.7.7....1..3...7.5.
1...4...7....1.8...667339
6.21648.6.......8.22...9.
.3....3............1.....
...2195...71.............
8....8..31..6.31.5..4...6
.6.1....2......7.......7.
.........5..1.2.9.9......
........3.8..9..64......3
.8...

output:

impossible

result:

ok 

Test #25:

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

input:

25 25 2 422
.4.......................
.....6....2..8....55.....
7.........7........63.1..
.9......8...2..4276......
.........61........7..944
...9..2..7.......1.41...5
...8..2......8...2...9.5.
......6.2.8....27...5....
.3.9......4....9..54....5
.8..6..26........8.2...1.
......8........3.4..4...7
.....

output:

impossible

result:

ok 

Test #26:

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

input:

25 25 3 922193402
7........................
....86...7.9...7.29..5...
....1......1...8.52...5..
7..2....9.3.37...........
.....35.1.86...9555.4..1.
...6.23...7....5.....5..9
8.7....95..65.1.7.....38.
........235............21
5559.2.72.........2...751
...44.527.4.8....8.95....
...7........8...5........

output:

37.150902636

result:

ok 

Test #27:

score: 0
Accepted
time: 2ms
memory: 16536kb

input:

25 25 3 789168379
......5..................
....6.2.......8.3.28.4.2.
5.....6.88....9...72.2...
..4..8.........1..4...5.4
8773994.3.6.1...1..75...7
2629...79.9.1411.........
.....791.......5..917.6.4
..17.72..9....5.95....9..
...5........7.3.25.4....9
.69..1.....3.....46573...
7......465.69.3..38..8...

output:

31.150902636

result:

ok 

Test #28:

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

input:

25 25 3 242
............6............
................8.......3
...7.......9.....8.......
........2................
..............6..96.....2
..1.....2..........9.....
.....7....6........1..5..
...........9.4...4.......
....5....................
..............53.........
................1......8.
.....

output:

impossible

result:

ok 

Test #29:

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

input:

25 25 3 434
..2......................
........................5
............3.....3......
.......8.............9...
3..........9.............
.....4..........61.......
..3......................
.....4..............6..1.
.18......................
6........................
...........43...........5
1....

output:

impossible

result:

ok 

Test #30:

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

input:

22 24 3 5550
........1...............
.6.756811649178....7663.
.88..7..55....5..8.1748.
.9.1..9.7243.868.6.....4
3765..93.24..2..1971.9..
7154..959.4...9.2..33.9.
7.673.578.712...59578.97
662....33..867.466.37.99
..5.3.616..1252.7.9317..
.51.9.6..994471.5.932..9
4.3178.2..48.16.43831.8.
....7999.88....

output:

21.236067977

result:

ok 

Test #31:

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

input:

25 25 1 1000000000
........................1
111.111.111.111.111.111.1
1.1.1.1.1.1.1.1.1.1.1.1.1
1.1.1.1.1.1.1.1.1.1.1.1.1
1.1.1.1.1.1.1.1.1.1.1.1.1
1.1.1.1.1.1.1.1.1.1.1.1.1
1.1.1.1.1.1.1.1.1.1.1.1.1
1.1.1.1.1.1.1.1.1.1.1.1.1
1.1.1.1.1.1.1.1.1.1.1.1.1
1.1.1.1.1.1.1.1.1.1.1.1.1
1.1.1.1.1.1.1.1.1.1.1...

output:

312.000000000

result:

ok 

Test #32:

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

input:

10 10 1 100
..........
.....1....
....11....
....11....
....11....
....11....
....11....
....11....
....1.....
..........

output:

8.000000000

result:

ok 

Test #33:

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

input:

10 10 1 100
..........
.....1....
.....1....
.....1....
.....1....
.....1....
.....1....
.....1....
.....1....
..........

output:

7.000000000

result:

ok 

Test #34:

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

input:

2 1 1 18
9
9

output:

1.000000000

result:

ok 

Test #35:

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

input:

2 1 3 18
9
9

output:

1.000000000

result:

ok 

Test #36:

score: 0
Accepted
time: 2ms
memory: 14320kb

input:

25 25 3 470510254
.........................
.........................
.........................
.........................
.........................
......1..................
.......3.............1...
..............9..........
........6....1...9...9...
.........8.415...........
........6.....1....8.....

output:

26.144329926

result:

ok 

Test #37:

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

input:

25 25 1 321
..1......................
..1..111...111...111.....
.11.1191..1191..1191..111
11.11..1911.11.11..191191
1.11...111.11.11...111.11
1.19111...11.11.111...11.
1.11191..11.11.1191..11..
11...11.11..1911.11.11...
91..11.11...111.11.11.111
11.11.11.111...11..191191
19.19.191191..11...111.11
11...

output:

320.000000000

result:

ok 

Test #38:

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

input:

25 25 1 321
..1......................
..1..111...111...111.....
.11.1161..1161..1161..111
11.11..1611.11.11..161161
1.11...111.11.11...111.11
1.16111...11.11.111...11.
1.11161..11.11.1161..11..
11...11.11..1611.11.11...
61..11.11...111.11.11.111
11.11.11.111...11..161161
16.16.161161..11...111.11
11...

output:

320.000000000

result:

ok 

Test #39:

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

input:

25 25 1 1000000000
..1......................
..1..111...111...111.....
.11.1191..1191..1191..111
11.11..1911.11.11..191191
1.11...111.11.11...111.11
1.19111...11.11.111...11.
1.11191..11.11.1191..11..
11...11.11..1911.11.11...
91..11.11...111.11.11.111
11.11.11.111...11..191191
19.19.191191..11...11...

output:

212.000000000

result:

ok 

Test #40:

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

input:

25 25 1 320
..1......................
..1..111...111...111.....
.11.1191..1191..1191..111
11.11..1911.11.11..191191
1.11...111.11.11...111.11
1.19111...11.11.111...11.
1.11191..11.11.1191..11..
11...11.11..1911.11.11...
91..11.11...111.11.11.111
11.11.11.111...11..191191
19.19.191191..11...111.11
11...

output:

impossible

result:

ok 

Test #41:

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

input:

10 10 1 100
..........
.....1....
.....1....
.....1....
.....1....
..........
.....1....
.....1....
.....1....
..........

output:

impossible

result:

ok 

Test #42:

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

input:

10 10 1 100
..........
.....1....
..........
..........
..........
..........
..........
..........
.....1....
..........

output:

impossible

result:

ok 

Test #43:

score: 0
Accepted
time: 2ms
memory: 28708kb

input:

25 25 1 1000000000
...9.....................
..99.999...999...999..999
.99.99.9..99.9..99.9..9.9
99.99.99.99.99.99.99.99.9
9.99.99.99.99.99.99.99.99
999.99.99.99.99.99.99.99.
...99.99.99.99.99.99.99..
..99.99.99.99.99.99.99...
.99.99.99.99.99.99.99.999
99.99.99.99.99.99.99.99.9
9.99.99.99.99.99.99.9...

output:

361.000000000

result:

ok 

Test #44:

score: 0
Accepted
time: 2ms
memory: 30540kb

input:

25 25 1 360
...1.....................
..11.111...111...111.....
.11.1191..1191..1191..111
11.11.11.11.11.11.11.1191
1911.11.11.11.11.11.11.11
111.11.11.11.11.11.11.11.
...11.11.11.11.11.11.11..
..11.11.11.11.11.11.11...
.11.11.11.11.11.11.11.111
11.11.11.11.11.11.11.1191
1911.11.11.11.11.11.11.11
11...

output:

359.000000000

result:

ok 

Test #45:

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

input:

25 25 1 1000000000
...1.....................
..11.111...111...111..111
.11.1191..1191..1191..191
11.11.11.11.11.11.11.11.1
1911.11.11.11.11.11.11.11
111.11.11.11.11.11.11.11.
...11.11.11.11.11.11.11..
..11.11.11.11.11.11.11...
.11.11.11.11.11.11.11.111
11.11.11.11.11.11.11.1191
1911..1.11..1.11..1.1...

output:

177.000000000

result:

ok