#include <bits/stdc++.h>
#include "wombats.h"
#define F first
#define S second
using namespace std;
const int N = 5e3 + 10 , M = 2e2 + 10 , Sq = 37 , inf = 1e9 + 10 , TOF = N / Sq + 10;
int r , c , h[N][M] , v[N][M] , nex[TOF][M][M] , adj[M][M] , ans[M][M] , dis[N][M] , dis2[TOF][M] , las;
bool is_update , marked[N][M];
void Dij(int num , int Qs)
{
int Ps = num * Sq , R = min(r - 1 , Ps + Sq);
las = max(las , num);
for(int i = Ps ; i <= R ; i++) for(int j = 0 ; j < c ; j++)
{
marked[i][j] = false;
dis[i][j] = inf;
}
dis[Ps][Qs] = 0;
priority_queue <pair<int , pair<int , int>> , vector <pair<int , pair<int , int>>> , greater<pair<int , pair<int , int>>>> pq;
pq.push({Ps , {0 , Qs}});
while(!pq.empty())
{
auto now = pq.top(); pq.pop();
int D = now.S.F , p = now.F , q = now.S.S;
if(marked[p][q])
continue;
marked[p][q] = true;
if(q + 1 < c && D + h[p][q] < dis[p][q + 1])
{
dis[p][q + 1] = D + h[p][q];
pq.push({p , {dis[p][q + 1] , q + 1}});
}
if(q - 1 >= 0 && D + h[p][q - 1] < dis[p][q - 1])
{
dis[p][q - 1] = D + h[p][q - 1];
pq.push({p , {dis[p][q - 1] , q - 1}});
}
if(p + 1 <= R && D + v[p][q] < dis[p + 1][q])
{
dis[p + 1][q] = D + v[p][q];
pq.push({p + 1 , {dis[p + 1][q] , q}});
}
}
for(int i = 0 ; i < c ; i++)
{
//cout << Ps << " " << Qs << " " << R << " " << i << " : " << dis[R][i] << endl;
nex[num][Qs][i] = dis[R][i];
}
if(num == 0)
{
for(int i = 0 ; i < c ; i++)
adj[Qs][i] = dis[Ps][i];
}
}
void Solve(int Qs)
{
for(int i = 0 ; i < las + 2 ; i++) for(int j = 0 ; j < c ; j++)
{
dis2[i][j] = inf;
}
for(int i = 0 ; i < c ; i++)
dis2[0][i] = adj[Qs][i];
for(int i = 0 ; i <= las ; i++)
{
for(int j = 0 ; j < c ; j++) for(int k = 0 ; k < c ; k++)
{
dis2[i + 1][k] = min(dis2[i + 1][k] , dis2[i][j] + nex[i][j][k]);
//cout << i << " " << j << " " << k << " " << dis2[i][j] << " " << nex[i][j][k] << endl;
}
}
for(int i = 0 ; i < c ; i++)
{
//cout << Qs << " " << i << " : " << dis2[las + 1][i] << endl;
ans[Qs][i] = dis2[las + 1][i];
}
}
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 + 1 < C ; j++)
h[i][j] = H[i][j];
for(int i = 0 ; i + 1 < R ; i++) for(int j = 0 ; j < C ; j++)
v[i][j] = V[i][j];
for(int i = 0 ; i < R ; i += Sq) for(int j = 0 ; j < C ; j++)
Dij(i / Sq , j);
}
void changeH(int P , int Q , int W)
{
is_update = false;
h[P][Q] = W;
for(int j = 0 ; j < c ; j++)
{
Dij(P / Sq , j);
if(P > 0 && P % Sq == 0)
Dij((P - 1) / Sq , j);
}
}
void changeV(int P , int Q , int W)
{
is_update = false;
v[P][Q] = W;
for(int j = 0 ; j < c ; j++)
Dij(P / Sq , j);
}
int escape(int v1 , int v2)
{
if(!is_update)
{
for(int i = 0 ; i < c ; i++)
Solve(i);
is_update = true;
}
return ans[v1][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 |
6 ms |
14172 KB |
Output is correct |
2 |
Correct |
6 ms |
14160 KB |
Output is correct |
3 |
Correct |
44 ms |
16532 KB |
Output is correct |
4 |
Correct |
7 ms |
14168 KB |
Output is correct |
5 |
Correct |
7 ms |
14172 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
1 ms |
592 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
40 ms |
2596 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2744 ms |
1312 KB |
Output is correct |
2 |
Correct |
3275 ms |
1384 KB |
Output is correct |
3 |
Correct |
3999 ms |
1412 KB |
Output is correct |
4 |
Correct |
3802 ms |
1412 KB |
Output is correct |
5 |
Correct |
3773 ms |
1400 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
19958 ms |
1396 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
22360 KB |
Output is correct |
2 |
Correct |
14 ms |
22460 KB |
Output is correct |
3 |
Correct |
11 ms |
22360 KB |
Output is correct |
4 |
Correct |
30 ms |
23140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2694 ms |
1360 KB |
Output is correct |
2 |
Correct |
3200 ms |
1400 KB |
Output is correct |
3 |
Correct |
3538 ms |
1360 KB |
Output is correct |
4 |
Correct |
3448 ms |
1332 KB |
Output is correct |
5 |
Correct |
3769 ms |
1320 KB |
Output is correct |
6 |
Correct |
13 ms |
22276 KB |
Output is correct |
7 |
Correct |
12 ms |
22364 KB |
Output is correct |
8 |
Correct |
13 ms |
22244 KB |
Output is correct |
9 |
Correct |
37 ms |
23136 KB |
Output is correct |
10 |
Correct |
5 ms |
15964 KB |
Output is correct |
11 |
Correct |
5 ms |
16004 KB |
Output is correct |
12 |
Correct |
44 ms |
17580 KB |
Output is correct |
13 |
Correct |
7 ms |
15964 KB |
Output is correct |
14 |
Correct |
6 ms |
15964 KB |
Output is correct |
15 |
Correct |
1 ms |
6488 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
41 ms |
7496 KB |
Output is correct |
26 |
Correct |
2 ms |
6492 KB |
Output is correct |
27 |
Correct |
18550 ms |
7228 KB |
Output is correct |
28 |
Execution timed out |
20066 ms |
33508 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2754 ms |
7080 KB |
Output is correct |
2 |
Correct |
3275 ms |
9044 KB |
Output is correct |
3 |
Correct |
3577 ms |
7252 KB |
Output is correct |
4 |
Correct |
3426 ms |
7296 KB |
Output is correct |
5 |
Correct |
3714 ms |
7256 KB |
Output is correct |
6 |
Correct |
12 ms |
22360 KB |
Output is correct |
7 |
Correct |
12 ms |
22364 KB |
Output is correct |
8 |
Correct |
12 ms |
22320 KB |
Output is correct |
9 |
Correct |
31 ms |
23896 KB |
Output is correct |
10 |
Correct |
5 ms |
15964 KB |
Output is correct |
11 |
Correct |
5 ms |
15964 KB |
Output is correct |
12 |
Correct |
42 ms |
18772 KB |
Output is correct |
13 |
Correct |
5 ms |
15964 KB |
Output is correct |
14 |
Correct |
5 ms |
15888 KB |
Output is correct |
15 |
Correct |
12945 ms |
54632 KB |
Output is correct |
16 |
Execution timed out |
20064 ms |
49856 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |