QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225132 | #3514. Bouldering | hagry# | WA | 71ms | 78308kb | C++14 | 2.6kb | 2023-10-24 00:29:37 | 2023-10-24 00:29:37 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define MP make_pair
#define all(x) x.begin(),x.end()
#define Hagry ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using ld = long double;
const ld OO = 1e15;
const int N = 2e5 + 5;
const int H = 25 + 4;
const int maxS = 6e3 + 5;
int h, w, r, s;
char grid[H][H];
ld dp[H][H][maxS];
int vis[H][H][maxS], vid;
vector<pair<pi, int>> adj[H][H];
pi start, target;
ld solve(int i, int j, int remS) {
int cost = (grid[i][j] - '0');
remS -= cost;
if(remS < 0)return OO;
if(MP(i, j) == target)
return 0;
ld &ret = dp[i][j][remS];
if(vis[i][j][remS] == vid)
return ret;
vis[i][j][remS] = vid;
ret = OO;
for(auto e:adj[i][j]){
if(remS >= cost)
ret = min(ret, sqrt((double)e.S) + solve(e.F.F, e.F.S, remS));
}
return ret;
}
void TC() {
++vid;
cin >> h >> w >> r >> s;
target = {-1, -1};
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
cin >> grid[i][j];
if (grid[i][j] != '.') {
if (target == MP(-1, -1))
target = MP(i, j);
start = MP(i, j);
}
}
}
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (grid[i][j] == '.')continue;
for (int d1 = -3; d1 <= 3; ++d1) {
for (int d2 = -3; d2 <= 3; ++d2) {
int newI = d1 + i;
int newJ = d2 + j;
if (newI < 0 || newI >= h ||
newJ < 0 || newJ >= w ||
grid[newI][newJ] == '.')
continue;
int distSq = abs(d1) * abs(d1) + abs(d2) * abs(d2);
if (r * r < distSq)continue;
adj[i][j].push_back(MP(MP(newI, newJ), distSq));
}
}
}
}
s = min(s, maxS);
ld ans = solve(start.F, start.S, s);
if (ans >= OO)
cout << "impossible\n";
else
cout << fixed << setprecision(9) << ans;
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
Hagry
int t = 1;
// cin >> t;
while (t--) {
TC();
cout << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 20108kb
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: 3ms
memory: 16180kb
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: 9584kb
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: 11904kb
input:
5 5 1 100 ....1 .1111 .1.9. .119. ..1..
output:
6.000000000
result:
ok
Test #5:
score: 0
Accepted
time: 2ms
memory: 9920kb
input:
6 7 3 10 ..6.... ..1.... ....... .5..1.. ....... ..1....
output:
6.656854249
result:
ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
2 18 2 5 .............1.... ...............9..
output:
impossible
result:
ok
Test #7:
score: 0
Accepted
time: 71ms
memory: 78308kb
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: 1ms
memory: 5520kb
input:
2 18 2 5 .............9.... ...............1..
output:
impossible
result:
ok
Test #9:
score: -100
Wrong Answer
time: 1ms
memory: 5648kb
input:
3 3 2 7 ..3 ... ..4
output:
impossible
result:
wrong answer