#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define X real()
#define Y imag()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define MOD1 1000000009
#define sqr(x) sqr((x)*(x))
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
#ifdef BE_DEBUG
#define debug(...) cerr << "\033[1;31m(" << #__VA_ARGS__ << "):\033[0m", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
int h[5000][200];
int v[5000][200];
priority_queue<pair<int,pair<int,int> > > pq;
int r,c;
int dp[5002][3][5];
void upd() {
dp[0][0][0] = 0;
dp[0][0][1] = h[0][0];
for(int i = 1; i < r; i ++) {
if(dp[i - 1][0][0] + v[i - 1][0] <= dp[i - 1][0][1] + v[i - 1][1]) {
dp[i][0][0] = dp[i - 1][0][0] + v[i - 1][0];
dp[i][0][1] = min(dp[i - 1][0][1] + v[i - 1][1], dp[i][0][0] + h[i][0]);
}
else {
dp[i][0][1] = dp[i - 1][0][1] + v[i - 1][1];
dp[i][0][0] = min(dp[i - 1][0][0] + v[i - 1][0], dp[i][0][1] + h[i][0]);
}
}
//
dp[0][1][0] = h[0][0];
dp[0][1][1] = 0;
for(int i = 1; i < r; i ++) {
if(dp[i - 1][1][0] + v[i - 1][0] <= dp[i - 1][1][1] + v[i - 1][1]) {
dp[i][1][0] = dp[i - 1][1][0] + v[i - 1][0];
dp[i][1][1] = min(dp[i - 1][1][1] + v[i - 1][1], dp[i][1][0] + h[i][0]);
}
else {
dp[i][1][1] = dp[i - 1][1][1] + v[i - 1][1];
dp[i][1][0] = min(dp[i - 1][1][0] + v[i - 1][0], dp[i][1][1] + h[i][0]);
}
}
}
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 - 1; j ++) {
h[i][j] = H[i][j];
}
}
for(int i = 0; i < R - 1; i ++) {
for(int j = 0; j < C; j ++) {
v[i][j] = V[i][j];
}
}
if(c == 2) upd();
}
void changeH(int P, int Q, int W) {
/* ... */
h[P][Q] = W;
if(c == 2) upd();
}
void changeV(int P, int Q, int W) {
/* ... */
v[P][Q] = W;
if(c == 2) upd();
}
int escape(int V1, int V2) {
if(c == 2) return dp[r - 1][V1][V2];
while(pq.size() > 0) pq.pop();
pq.push({0,{0,V1}});
bool visited[r][c];
memset(visited,0,sizeof(visited));
while(pq.size() > 0) {
pair<int,pair<int,int> > p;
//cout << p.ff << ' ' << p.ss.ff << ' ' << p.ss.ss << '\n';
p = pq.top();
pq.pop();
if(visited[p.ss.ff][p.ss.ss] == 1) continue;
visited[p.ss.ff][p.ss.ss] = 1;
if(p.ss.ff == r - 1 && p.ss.ss == V2) return -p.ff;
if(p.ss.ss > 0 && visited[p.ss.ff][p.ss.ss - 1] == 0) {
pq.push({p.ff - h[p.ss.ff][p.ss.ss - 1],{p.ss.ff, p.ss.ss - 1}});
}
if(p.ss.ss + 1 < c && visited[p.ss.ff][p.ss.ss + 1] == 0) {
pq.push({p.ff - h[p.ss.ff][p.ss.ss],{p.ss.ff,p.ss.ss + 1}});
}
if(p.ss.ff + 1 < r && visited[p.ss.ff + 1][p.ss.ss] == 0) {
pq.push({p.ff - v[p.ss.ff][p.ss.ss],{p.ss.ff + 1, p.ss.ss}});
}
}
return 0;
}
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 |
47 ms |
8124 KB |
Output is correct |
2 |
Correct |
47 ms |
8020 KB |
Output is correct |
3 |
Correct |
17136 ms |
10508 KB |
Output is correct |
4 |
Correct |
48 ms |
8148 KB |
Output is correct |
5 |
Correct |
49 ms |
8152 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
17 ms |
404 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
20 ms |
340 KB |
Output is correct |
7 |
Correct |
20 ms |
340 KB |
Output is correct |
8 |
Correct |
17 ms |
396 KB |
Output is correct |
9 |
Correct |
19 ms |
400 KB |
Output is correct |
10 |
Correct |
17 ms |
400 KB |
Output is correct |
11 |
Correct |
9073 ms |
2068 KB |
Output is correct |
12 |
Correct |
20 ms |
396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
632 KB |
Output is correct |
2 |
Correct |
184 ms |
836 KB |
Output is correct |
3 |
Correct |
167 ms |
832 KB |
Output is correct |
4 |
Correct |
166 ms |
844 KB |
Output is correct |
5 |
Correct |
168 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
190 ms |
752 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
16212 KB |
Output is correct |
2 |
Correct |
36 ms |
16248 KB |
Output is correct |
3 |
Correct |
47 ms |
16232 KB |
Output is correct |
4 |
Correct |
80 ms |
16928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
632 KB |
Output is correct |
2 |
Correct |
181 ms |
952 KB |
Output is correct |
3 |
Correct |
167 ms |
724 KB |
Output is correct |
4 |
Correct |
166 ms |
724 KB |
Output is correct |
5 |
Correct |
164 ms |
724 KB |
Output is correct |
6 |
Correct |
44 ms |
16304 KB |
Output is correct |
7 |
Correct |
38 ms |
16292 KB |
Output is correct |
8 |
Correct |
42 ms |
16212 KB |
Output is correct |
9 |
Correct |
77 ms |
17656 KB |
Output is correct |
10 |
Correct |
50 ms |
8148 KB |
Output is correct |
11 |
Correct |
47 ms |
8148 KB |
Output is correct |
12 |
Correct |
17557 ms |
11040 KB |
Output is correct |
13 |
Correct |
47 ms |
8148 KB |
Output is correct |
14 |
Correct |
47 ms |
8152 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
17 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
19 ms |
400 KB |
Output is correct |
21 |
Correct |
19 ms |
340 KB |
Output is correct |
22 |
Correct |
16 ms |
316 KB |
Output is correct |
23 |
Correct |
19 ms |
324 KB |
Output is correct |
24 |
Correct |
17 ms |
404 KB |
Output is correct |
25 |
Correct |
9300 ms |
2628 KB |
Output is correct |
26 |
Correct |
22 ms |
340 KB |
Output is correct |
27 |
Correct |
198 ms |
748 KB |
Output is correct |
28 |
Execution timed out |
20040 ms |
17812 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
166 ms |
632 KB |
Output is correct |
2 |
Correct |
180 ms |
864 KB |
Output is correct |
3 |
Correct |
166 ms |
724 KB |
Output is correct |
4 |
Correct |
168 ms |
716 KB |
Output is correct |
5 |
Correct |
164 ms |
728 KB |
Output is correct |
6 |
Correct |
44 ms |
16304 KB |
Output is correct |
7 |
Correct |
41 ms |
16212 KB |
Output is correct |
8 |
Correct |
44 ms |
16212 KB |
Output is correct |
9 |
Correct |
80 ms |
17748 KB |
Output is correct |
10 |
Correct |
48 ms |
8148 KB |
Output is correct |
11 |
Correct |
48 ms |
8156 KB |
Output is correct |
12 |
Correct |
17108 ms |
11104 KB |
Output is correct |
13 |
Correct |
48 ms |
8148 KB |
Output is correct |
14 |
Correct |
48 ms |
8148 KB |
Output is correct |
15 |
Correct |
1122 ms |
18480 KB |
Output is correct |
16 |
Execution timed out |
20068 ms |
18320 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |