#include "wombats.h"
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int r, c;
const int sq = 300;
int h[5000][200];
int v[5000][200];
int dis[5000/sq+5][200][sq+5][200];
void dijkstra(int beg, int end, int imp, int dis[5000][200]){
for(int i = beg; i <= end; ++i)
for(int j = 0; j < c; ++j)
dis[i-beg][j] = 1e9+7;
priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> pq;
dis[end-beg][imp] = 0;
pq.push({0, {end, imp}});
while(pq.size()){
int d = pq.top().ff;
int x = pq.top().ss.ff;
int y = pq.top().ss.ss;
pq.pop();
if(d > dis[x-beg][y])
continue;
if(x > beg && dis[x-1-beg][y] > d + v[x-1][y]){
dis[x-1-beg][y] = d + v[x-1][y];
pq.push({dis[x-1-beg][y], {x-1, y}});
}
if(y > 0 && dis[x-beg][y-1] > d + h[x][y-1]){
dis[x-beg][y-1] = d + h[x][y-1];
pq.push({dis[x-beg][y-1], {x, y-1}});
}
if(y < c-1 && dis[x-beg][y+1] > d + h[x][y]){
dis[x-beg][y+1] = d + h[x][y];
pq.push({dis[x-beg][y+1], {x, y+1}});
}
}
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
r = R;
c = C;
for(int i = 0; i < r; ++i)
for(int j = 0; j < c; ++j){
h[i][j] = H[i][j];
v[i][j] = V[i][j];
}
for(int i = 0; i < r; i += sq)
for(int j = 0; j < c; ++j)
dijkstra(i, min(i+sq, r-1), j, dis[i/sq][j]);
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
int gr = P/sq;
for(int j = 0; j < c; ++j)
dijkstra(gr*sq, min(r-1, (gr+1)*sq), j, dis[gr][j]);
if(gr > 0 && P%sq == 0){
--gr;
for(int j = 0; j < c; ++j)
dijkstra(gr*sq, min(r-1, (gr+1)*sq), j, dis[gr][j]);
}
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
int gr = P/sq;
for(int j = 0; j < c; ++j)
dijkstra(gr*sq, min(r-1, (gr+1)*sq), j, dis[gr][j]);
}
int escape(int V1, int V2) {
vector<int> curd(c, 1e9+7);
vector<int> newd(c, 1e9+7);
curd[V1] = 0;
for(int i = 0; i < r; i += sq){
for(int j = 0; j < c; ++j)
for(int k = 0; k < c; ++k)
newd[k] = min(newd[k], curd[j]+dis[i/sq][k][0][j]);
for(int j = 0; j < c; ++j){
curd[j] = newd[j];
newd[j] = 1e9+7;
}
}
assert(curd[V2] >= 0);
return curd[V2];
}
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
15 | int res;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
16256 KB |
Output is correct |
2 |
Correct |
14 ms |
16128 KB |
Output is correct |
3 |
Correct |
132 ms |
19068 KB |
Output is correct |
4 |
Correct |
15 ms |
16128 KB |
Output is correct |
5 |
Correct |
17 ms |
16128 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
768 KB |
Output is correct |
5 |
Correct |
2 ms |
768 KB |
Output is correct |
6 |
Correct |
2 ms |
768 KB |
Output is correct |
7 |
Correct |
3 ms |
768 KB |
Output is correct |
8 |
Correct |
2 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
2 ms |
768 KB |
Output is correct |
11 |
Correct |
209 ms |
2008 KB |
Output is correct |
12 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15100 ms |
8952 KB |
Output is correct |
2 |
Execution timed out |
20055 ms |
9428 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
24056 KB |
Output is correct |
2 |
Correct |
94 ms |
24064 KB |
Output is correct |
3 |
Correct |
51 ms |
24184 KB |
Output is correct |
4 |
Correct |
116 ms |
25464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15206 ms |
8952 KB |
Output is correct |
2 |
Execution timed out |
20067 ms |
9088 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15083 ms |
8952 KB |
Output is correct |
2 |
Execution timed out |
20086 ms |
8920 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |