QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#61004 | #3514. Bouldering | abdelrahman001 | WA | 2694ms | 161404kb | C++20 | 2.0kb | 2022-11-09 04:08:42 | 2022-11-09 04:08:43 |
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];
vector<array<int, 3>> g[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(auto k : g[curi][curj]) {
int ni = k[0];
int nj = k[1];
ld ndis = dis + sqrt(k[2]);
int c = a[ni][nj] - '0';
if(c + curs > s)
continue;
int cs = c + curs;
if(ndis < d[ni][nj][cs]) {
d[ni][nj][cs] = ndis;
q.push({-ndis, {cs, ni, nj}});
}
}
}
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 = 1;i < n;i++) {
for(int j = 0;j < m;j++) {
for(int x = i;x >= 0;x--) {
for(int y = 0;y < m;y++) {
if(a[i][j] == '.' || a[x][y] == '.')
continue;
int dis = sqr(i - x) + sqr(j - y);
if(dis > sqr(r))
continue;
g[i][j].push_back({x, y, dis});
}
}
}
}
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: 0ms
memory: 38480kb
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: 34512kb
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: 32056kb
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: 15988kb
input:
5 5 1 100 ....1 .1111 .1.9. .119. ..1..
output:
6.000000000
result:
ok
Test #5:
score: 0
Accepted
time: 2ms
memory: 13928kb
input:
6 7 3 10 ..6.... ..1.... ....... .5..1.. ....... ..1....
output:
6.656854249
result:
ok
Test #6:
score: 0
Accepted
time: 3ms
memory: 9560kb
input:
2 18 2 5 .............1.... ...............9..
output:
impossible
result:
ok
Test #7:
score: -100
Wrong Answer
time: 2694ms
memory: 161404kb
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:
impossible
result:
wrong answer