QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#60966#3514. Boulderingabdelrahman001#WA 3ms3612kbC++201.9kb2022-11-08 22:38:572022-11-08 22:38:59

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-08 22:38:59]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 3612kb
  • [2022-11-08 22:38:57]
  • Submitted

answer

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int N = 50 + 5;
int n, m, r, s, mn = 1e9;
pair<ld, int> d[N][N];
char a[N][N];
int sqr(int x) {
	return x * x;
}
ld dij(int i, int j) {
	priority_queue<pair<ld, array<int, 3>>> q;
	for(int i = 0;i < n;i++) {
		for(int j = 0;j < m;j++) {
			d[i][j] = {1e9, 1e9};
		}
	}
	d[i][j] = {0, 0};
	q.push({0, {0, i, j}});
	while(!q.empty()) {
		ld dis = -q.top().first;
		int curi = q.top().second[1];
		int curj = q.top().second[2];
		int curs = -q.top().second[0];
		q.pop();
		if(d[curi][curj].first < dis || d[curi][curj].first == dis && d[curi][curj].second < curs)
			continue;
		if(curi == mn)
			return dis;
		for(int k = curi;k >= 0;k--) {
			for(int p = 0;p < m;p++) {
				if(a[k][p] == '.')
					continue;
				int ndis = sqr(k - curi) + sqr(p - curj);
				if(ndis > sqr(r))
					continue;
				int c = a[k][p] - '0';
				if(c + curs > s)
					continue;
				if(dis + sqrt(ndis) < d[k][p].first || dis + sqrt(ndis) == d[k][p].first && c + curs < d[k][p].second) {
					d[k][p] = {dis + sqrt(ndis), c + curs};
					q.push({-d[k][p].first, {-d[k][p].second, k, p}});
				}
			}
		}
	}
	return 1e15;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m >> r >> s;
    for(int i = 0;i < n;i++) {
		for(int j = 0;j < m;j++) {
			cin >> a[i][j];
			if(a[i][j] != '.')
				mn = min(mn, i);
		}
	}
	for(int i = n - 1;i >= 0;i--) {
		for(int j = 0;j < m;j++) {
			if(a[i][j] != '.') {
				ld ans = dij(i, j);
				if(ans == 1e15)
					cout << "impossible";
				else
					cout << fixed << setprecision(9) << ans << endl;
				return 0;
			}
		}
	}
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3612kb

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: 2ms
memory: 3548kb

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: 2ms
memory: 3304kb

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: 2ms
memory: 3520kb

input:

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

output:

6.000000000

result:

ok 

Test #5:

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

input:

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

output:

impossible

result:

wrong answer