QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#61002 | #3514. Bouldering | abdelrahman001 | TL | 5ms | 38424kb | C++20 | 1.8kb | 2022-11-09 04:02:59 | 2022-11-09 04:03:02 |
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;
const int M = 6e3 + 5;
int n, m, r, s, mn = 1e9;
ld d[N][N][M];
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++) {
for(int k = 0;k <= s;k++)
d[i][j][k] = 1e9;
}
}
int c = a[i][j] - '0';
d[i][j][c] = 0;
q.push({0, {c, 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][curs] < dis)
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;
ld cdis = dis + sqrt(ndis);
int cs = c + curs;
if(cdis < d[k][p][cs]) {
d[k][p][cs] = cdis;
q.push({-d[k][p][cs], {cs, 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: 38424kb
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: 28100kb
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: 32040kb
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: 3ms
memory: 11744kb
input:
5 5 1 100 ....1 .1111 .1.9. .119. ..1..
output:
6.000000000
result:
ok
Test #5:
score: 0
Accepted
time: 5ms
memory: 15836kb
input:
6 7 3 10 ..6.... ..1.... ....... .5..1.. ....... ..1....
output:
6.656854249
result:
ok
Test #6:
score: 0
Accepted
time: 3ms
memory: 7508kb
input:
2 18 2 5 .............1.... ...............9..
output:
impossible
result:
ok
Test #7:
score: -100
Time Limit Exceeded
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....