#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz size()
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
int rows[5000][200], cols[5000][200],pre[5001][201],ans[5001][201];
int r,c;
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++) rows[i][j] = H[i][j];
}
for(int i = 0; i < c; i++)
{
for(int j = 0; j < r-1; j++)
{
cols[j][i] = V[j][i];
}
}
}
void changeH(int P, int Q, int W) {
rows[P][Q] = W;
}
void changeV(int P, int Q, int W) {
cols[P][Q] = W;
}
int escape(int V1, int V2) {
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++) ans[i][j] = 0;
}
for(int i = 0; i < r; i++)
{
for(int j = 1; j < c; j++)
{
pre[i][j] = pre[i][j-1]+rows[i][j-1];
}
}
for(int i = 0; i < c; i++)
{
if(i==V1) ans[0][V1] = 0;
else if(i<V1) ans[0][i] = pre[0][V1]-pre[0][i];
else ans[0][i] = pre[0][i]-pre[0][V1];
// cout << ans[0][i] << " ";
}
//cout << endl;
for(int i = 1; i < r; i++)
{
for(int j = 0; j < c; j++)
{
ans[i][j] = 1e18;
for(int k = 0; k < c; k++)
{
if(k==j) ans[i][j] = min(ans[i][j],ans[i-1][k]+cols[i-1][k]);
else if(k<j) ans[i][j] = min(ans[i][j],ans[i-1][k]+cols[i-1][k]+pre[i][j]-pre[i][k]);
else ans[i][j] = min(ans[i][j],ans[i-1][k]+cols[i-1][k]+pre[i][k]-pre[i][j]);
}
}
}
//for(int i = 0; i < r; i++) {for(int j = 0; j < c; j++) cout << ans[i][j] << " "; cout << endl;}
int best = 1e9;
for(int i = 0; i < c-1 ;i++)
{
if(i==V2) best = min(best,ans[r-1][i]);
else if(i<V2) best = min(best,ans[r-1][i] + pre[r-1][V2]-pre[r-1][i]);
else best = min(best,ans[r-1][i]+pre[r-1][i]-pre[r-1][V2]);
}
return best;
}
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;
| ^~~
wombats.cpp: In function 'int escape(int, int)':
wombats.cpp:60:25: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
60 | ans[i][j] = 1e18;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
16984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
160 ms |
8872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
95 ms |
24020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
141 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
143 ms |
8868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |