QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#60965 | #3514. Bouldering | abdelrahman001# | WA | 2ms | 3612kb | C++20 | 1.9kb | 2022-11-08 22:35:59 | 2022-11-08 22:36:01 |
Judging History
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 - 1;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;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
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: 3608kb
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: 3416kb
input:
10 10 2 10 ...2...... .......... ...5.2.... .......... .....3.... ....5..... ..2....2.. ..1....... ....2..... ..1.......
output:
impossible
result:
ok
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3376kb
input:
5 5 1 100 ....1 .1111 .1.9. .119. ..1..
output:
impossible
result:
wrong answer