QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#198002 | #3514. Bouldering | beshoyhany# | TL | 323ms | 21096kb | C++20 | 4.3kb | 2023-10-02 23:20:08 | 2023-10-02 23:20:08 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("Ofast,no-stack-protector", "omit-frame-pointer", "inline", "-ffast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,fma,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>
#define ll long long
#define pp push_back
#define endl '\n'
#define all(x) x.begin(),x.end()
#define ld long double
#define PI acos(-1)
#define sin(a) sin((a)*PI/180)
#define cos(a) cos((a)*PI/180)
#define ones(x) __builtin_popcountll(x)
//#define int ll
using namespace std;
void Drakon() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#ifdef Clion
freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif
}
unsigned long long inf = 1e10;
const double EPS = 1e-6;
const int MOD = 1000000007, N = 30, LOG = 25;
ll gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll a, ll b) {
return (a * b) / __gcd(a, b);
}
ll mul(const ll &a, const ll &b) {
return (a % MOD + MOD) * (b % MOD + MOD) % MOD;
}
ll add(const ll &a, const ll &b) {
return (a + b + 2 * MOD) % MOD;
}
ll pw(ll x, ll y) {
ll ret = 1;
while (y > 0) {
if (y % 2 == 0) {
x = mul(x, x);
y = y / 2;
} else {
ret = mul(ret, x);
y = y - 1;
}
}
return ret;
}
int h, w, r, s;
char arr[N][N];
pair<int, int>top, bot;
vector<pair<pair<int, int>, double>>adj[N][N];
void dijkstra(){
double dist[h][w][3500];
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
for (int k = 0; k < 3500; ++k) {
dist[i][j][k] = 1e9;
}
}
}
dist[bot.first][bot.second][min(s, 3500 - 1)] = 0;
priority_queue<pair<pair<double, int>, pair<int, int>>, vector<pair<pair<double, int>, pair<int, int>>>, greater<>>q;
q.push({{0, min(s - (arr[bot.first][bot.second] - '0'), 3500 - 1)}, bot});
while (!q.empty()){
auto p = q.top();
q.pop();
int x = p.second.first, y = p.second.second, sta = p.first.second;
double d = p.first.first;
if(d - dist[x][y][sta] > EPS)continue;
for(auto v : adj[x][y]){
if(sta >= arr[v.first.first][v.first.second] - '0'){
if(dist[v.first.first][v.first.second][sta - (arr[v.first.first][v.first.second] - '0')] - (d + v.second) > EPS){
dist[v.first.first][v.first.second][sta - (arr[v.first.first][v.first.second] - '0')] = d + v.second;
q.push({{d + v.second, sta - (arr[v.first.first][v.first.second] - '0')}, v.first});
}
}
}
}
double ans = 1e9;
for (int i = 0; i <= min(s, 3500 - 1); ++i) {
ans = min(ans, dist[top.first][top.second][i]);
}
if(ans > 1e8){
cout << "impossible";
return;
}
cout << fixed << setprecision(10) << ans;
}
void solve() {
cin >> h >> w >> r >> s;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
cin >> arr[i][j];
}
}
bool found = false;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if(arr[i][j] != '.'){
top = {i, j};
found = true;
break;
}
}
if(found)break;
}
found = false;
for (int i = h - 1; i >= 0; --i) {
for (int j = 0; j < w; ++j) {
if(arr[i][j] != '.'){
bot = {i, j};
found = true;
break;
}
}
if(found)break;
}
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if(arr[i][j] == '.')continue;
for (int k = 0; k < h; ++k) {
for (int l = 0; l < w; ++l) {
if(k == i && l == j)continue;
if(arr[k][l] == '.')continue;;
int d = (i - k) * (i - k) + (j - l) * (j - l);
if(d <= r * r){
adj[i][j].pp({{k, l}, sqrt(d)});
}
}
}
}
}
dijkstra();
}
signed main() {
Drakon();
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7684kb
input:
12 11 3 11 ........... ........3.. .......3.1. ........... .......2... .....2..... .1.1....... .....2..... .1......... ...2....... .1......... ...........
output:
13.5432037669
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 7340kb
input:
8 16 3 15 ......1......... ....1..1.1...... ..2........1.... ...2......1..... .....4.1..2..1.. ................ .......1........ ................
output:
6.4142135624
result:
ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 6620kb
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: 1ms
memory: 4528kb
input:
5 5 1 100 ....1 .1111 .1.9. .119. ..1..
output:
6.0000000000
result:
ok
Test #5:
score: 0
Accepted
time: 1ms
memory: 4984kb
input:
6 7 3 10 ..6.... ..1.... ....... .5..1.. ....... ..1....
output:
6.6568542495
result:
ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 4568kb
input:
2 18 2 5 .............1.... ...............9..
output:
impossible
result:
ok
Test #7:
score: 0
Accepted
time: 142ms
memory: 21076kb
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.0000000000
result:
ok
Test #8:
score: 0
Accepted
time: 1ms
memory: 4628kb
input:
2 18 2 5 .............9.... ...............1..
output:
impossible
result:
ok
Test #9:
score: 0
Accepted
time: 1ms
memory: 4180kb
input:
3 3 2 7 ..3 ... ..4
output:
2.0000000000
result:
ok
Test #10:
score: 0
Accepted
time: 323ms
memory: 21096kb
input:
25 25 1 1000000000 ........................1 2547174745232875997886554 7965651126962942737771266 6728739299224693912515356 3892629154668465958161356 7224952531945412299918567 6652628797132321234345444 2166938247278479435464195 4614671371217599224792557 1652832422769863877435862 528832887161666938898...
output:
48.0000000000
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...