QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225128 | #3514. Bouldering | hagry# | TL | 1886ms | 803460kb | C++14 | 2.6kb | 2023-10-24 00:23:54 | 2023-10-24 00:23:54 |
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 = 7e4 + 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');
if(MP(i, j) == target)
return remS >= cost ? 0 : OO;
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 - cost));
}
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: 24484kb
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: 28536kb
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: 9876kb
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: 0ms
memory: 20196kb
input:
5 5 1 100 ....1 .1111 .1.9. .119. ..1..
output:
6.000000000
result:
ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 12008kb
input:
6 7 3 10 ..6.... ..1.... ....... .5..1.. ....... ..1....
output:
6.656854249
result:
ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 5760kb
input:
2 18 2 5 .............1.... ...............9..
output:
impossible
result:
ok
Test #7:
score: 0
Accepted
time: 976ms
memory: 519204kb
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: 5772kb
input:
2 18 2 5 .............9.... ...............1..
output:
impossible
result:
ok
Test #9:
score: 0
Accepted
time: 0ms
memory: 5964kb
input:
3 3 2 7 ..3 ... ..4
output:
2.000000000
result:
ok
Test #10:
score: 0
Accepted
time: 1886ms
memory: 803460kb
input:
25 25 1 1000000000 ........................1 2547174745232875997886554 7965651126962942737771266 6728739299224693912515356 3892629154668465958161356 7224952531945412299918567 6652628797132321234345444 2166938247278479435464195 4614671371217599224792557 1652832422769863877435862 528832887161666938898...
output:
48.000000000
result:
ok
Test #11:
score: -100
Time Limit Exceeded
input:
25 25 3 1000000000 ........................1 9726394797162243248412114 2389413121411497892345775 3536731263389491377529168 8539547197629558379487557 3476316664681454144237253 7167793883245166544976269 6551392597242556216495516 2913226341422851312188434 4794887856899463978185497 183788127159254461697...