#include "wombats.h"
#include <bits/stdc++.h>
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define all(x) x.begin() , x.end()
typedef long long ll;
using namespace std;
const int N = 6e3+5;
const long long oo = 1e18;
ll dx[] = {1 , -1 , 0} ;
ll dy[] = {0 , 0 , 1} ;
ll n , m , h[N][204] , v[N][204] , a[N][204] , cost[N] , sum , c , r ;
ll dis[105][105] ;
set < pair <ll, pair <ll, ll>> > st ;
void init(int R, int C, int H[5000][200], int V[5000][200]) {
n = R , m = C ;
for (int i = 0 ; i<n ; i++)
{
cost[i] = H[i][0];
for (int j = 0 ; j<m ; j++)
{
v[i][j] = V[i][j] , h[i][j] = H[i][j] ;
sum += v[i][j] ;
a[i][j] = v[i][j];
}
}
}
void changeH(int P, int Q, int W) {
h[P][Q] = W ;
cost[P] = W ;
}
void changeV(int P, int Q, int W) {
sum -= v[P][Q] ;
sum += W ;
v[P][Q] = W ;
a[P][Q] = W ;
}
ll dp[N][2][2] ;
ll bt (ll i , bool is , bool is2)
{
if (i == n)
return ((is != is2) * cost[n-1]) ;
ll &ret = dp[i][is][is2] ;
if (~ret)
return ret ;
ret = bt(i+1 , is , is2) + a[i][is] ;
ret = min(ret , bt(i+1 , !is , is2) + cost[i] + a[i][!is]);
return ret ;
}
int escape(int V1, int V2)
{
if (m == 1)
return sum ;
for (int i = 0 ; i<=n+9 ; i++)
{
dp[i][0][0] = -1 ;
dp[i][0][1] = -1 ;
dp[i][1][0] = -1 ;
dp[i][1][1] = -1 ;
}
if (m == 2)
return bt(0 , V1 , V2) ;
for (int p = 0 ; p<n ; p++)
for (int j = 0 ; j<m ; j++)
dis[p][j] = oo ;
st.insert({0 , {0 , V1}});
while (!st.empty())
{
pair <ll , pair <ll,ll>> pr = *st.begin() ;
st.erase(st.begin());
ll cos = pr.F , x = pr.S.F , y = pr.S.S ;
if (cos + v[x][y] < dis[x+1][y] && x+1 < n)
{
dis[x+1][y] = cos + v[x][y] ;
st.insert({dis[x+1][y] , {x+1 , y}});
}
if (cos + h[x][y] < dis[x][y+1] && y+1<m)
{
dis[x][y+1] = cos + h[x][y] ;
st.insert({dis[x][y+1] , {x , y+1}});
}
if (cos + h[x][y-1] < dis[x][y-1] && y-1 >= 0)
{
dis[x][y-1] = cos + h[x][y-1] ;
st.insert({dis[x][y-1] , {x , y-1}});
}
}
return dis[n-1][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 |
13 ms |
28244 KB |
Output is correct |
2 |
Correct |
14 ms |
28136 KB |
Output is correct |
3 |
Correct |
78 ms |
30936 KB |
Output is correct |
4 |
Correct |
13 ms |
28244 KB |
Output is correct |
5 |
Correct |
13 ms |
28244 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
22 ms |
468 KB |
Output is correct |
5 |
Correct |
13 ms |
496 KB |
Output is correct |
6 |
Correct |
15 ms |
468 KB |
Output is correct |
7 |
Correct |
23 ms |
468 KB |
Output is correct |
8 |
Correct |
21 ms |
448 KB |
Output is correct |
9 |
Correct |
25 ms |
468 KB |
Output is correct |
10 |
Correct |
22 ms |
508 KB |
Output is correct |
11 |
Correct |
11790 ms |
2944 KB |
Output is correct |
12 |
Correct |
27 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
199 ms |
1276 KB |
Output is correct |
2 |
Correct |
217 ms |
1484 KB |
Output is correct |
3 |
Correct |
191 ms |
1168 KB |
Output is correct |
4 |
Correct |
189 ms |
1108 KB |
Output is correct |
5 |
Correct |
189 ms |
1152 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
198 ms |
1224 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
32832 KB |
Output is correct |
2 |
Correct |
188 ms |
32812 KB |
Output is correct |
3 |
Correct |
161 ms |
32844 KB |
Output is correct |
4 |
Correct |
14507 ms |
34128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
189 ms |
1140 KB |
Output is correct |
2 |
Correct |
213 ms |
1464 KB |
Output is correct |
3 |
Correct |
194 ms |
1152 KB |
Output is correct |
4 |
Correct |
188 ms |
1108 KB |
Output is correct |
5 |
Correct |
190 ms |
1144 KB |
Output is correct |
6 |
Correct |
168 ms |
32824 KB |
Output is correct |
7 |
Correct |
163 ms |
32808 KB |
Output is correct |
8 |
Correct |
219 ms |
32836 KB |
Output is correct |
9 |
Correct |
14668 ms |
34276 KB |
Output is correct |
10 |
Correct |
13 ms |
28244 KB |
Output is correct |
11 |
Correct |
13 ms |
28244 KB |
Output is correct |
12 |
Correct |
76 ms |
30988 KB |
Output is correct |
13 |
Correct |
13 ms |
28152 KB |
Output is correct |
14 |
Correct |
14 ms |
28204 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
24 ms |
488 KB |
Output is correct |
19 |
Correct |
13 ms |
468 KB |
Output is correct |
20 |
Correct |
15 ms |
500 KB |
Output is correct |
21 |
Correct |
23 ms |
448 KB |
Output is correct |
22 |
Correct |
20 ms |
468 KB |
Output is correct |
23 |
Correct |
24 ms |
448 KB |
Output is correct |
24 |
Correct |
23 ms |
488 KB |
Output is correct |
25 |
Correct |
11904 ms |
2748 KB |
Output is correct |
26 |
Correct |
27 ms |
468 KB |
Output is correct |
27 |
Correct |
213 ms |
1348 KB |
Output is correct |
28 |
Execution timed out |
20048 ms |
36008 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
1108 KB |
Output is correct |
2 |
Correct |
215 ms |
1516 KB |
Output is correct |
3 |
Correct |
200 ms |
1172 KB |
Output is correct |
4 |
Correct |
186 ms |
1108 KB |
Output is correct |
5 |
Correct |
195 ms |
1148 KB |
Output is correct |
6 |
Correct |
156 ms |
32824 KB |
Output is correct |
7 |
Correct |
167 ms |
32844 KB |
Output is correct |
8 |
Correct |
171 ms |
32828 KB |
Output is correct |
9 |
Correct |
14543 ms |
34212 KB |
Output is correct |
10 |
Correct |
13 ms |
28244 KB |
Output is correct |
11 |
Correct |
12 ms |
28244 KB |
Output is correct |
12 |
Correct |
81 ms |
31052 KB |
Output is correct |
13 |
Correct |
13 ms |
28232 KB |
Output is correct |
14 |
Correct |
12 ms |
28244 KB |
Output is correct |
15 |
Incorrect |
450 ms |
42224 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |