#include "wombats.h"
#include<bits/stdc++.h>
using namespace std;
const int RMAX=5000, CMAX=200, BLOMAX=130;
int H[RMAX][CMAX], V[RMAX][CMAX], R, C, K=85, blo;
int dist[2*BLOMAX][CMAX][CMAX], pocz[BLOMAX], kon[BLOMAX], czy[BLOMAX*2];
int res[CMAX][CMAX];
void get_res(){
for(int i=0; i<C; i++){
for(int j=0; j<C; j++){
res[i][j]=dist[1][i][j];
}
for(int j=1; j<C; j++){
res[i][j]=min(res[i][j], res[i][j-1]+H[R-1][j-1]);
}
for(int j=C-2; j>=0; j--){
res[i][j]=min(res[i][j+1]+H[R-1][j], res[i][j]);
}
}
}
int escape(int V1, int V2) {
/*int ans=dist[1][V1][V2];
int sum=0;
for(int i=V2+1; i<C; i++){
sum+=H[R-1][i-1];
ans=min(ans, dist[1][V1][i]+sum);
}
sum=0;
for(int i=V2-1; i>=0; i--){
sum+=H[R-1][i];
ans=min(ans, dist[1][V1][i]+sum);
}*/
//cerr<<ans<<"\n";
return res[V1][V2];
}
void update(int num){
int tab[C][C];
for(int i=0; i<C; i++){
for(int j=0; j<C; j++){
tab[i][j]=(1e9)*(i!=j);
}
}
for(int r=pocz[num]; r<=kon[num]; r++){
for(int i=0; i<C; i++){
for(int j=1; j<C; j++){
tab[i][j]=min(tab[i][j], tab[i][j-1]+H[r][j-1]);
}
for(int j=C-2; j>=0; j--){
tab[i][j]=min(tab[i][j+1]+H[r][j], tab[i][j]);
}
for(int j=0; j<C; j++){
tab[i][j]+=V[r][j];
}
}
}
//cerr<<"\n";
//cerr<<num<<"\n";
for(int i=0; i<C; i++){
for(int j=0; j<C; j++){
//cerr<<tab[i][j]<<" \n"[j==C-1];
dist[blo+num][i][j]=tab[i][j];
}
}
//cerr<<"\n";
}
void lacz(int v){
if(!czy[v])return;
int l=v+v, r=v+v+1;
if(!czy[r]){
for(int i=0; i<C; i++){
for(int j=0; j<C; j++){
dist[v][i][j]=dist[l][i][j];
}
}
}
else{
vector<int> mini(C, 1e9);
for(int i=0; i<C; i++){
for(int j=0; j<C; j++){
mini[i]=min(mini[i], dist[r][j][i]);
}
}
for(int i=0; i<C; i++){
vector<pair<int, int>> kol(C);
for(int j=0; j<C; j++){
kol[j]={dist[l][i][j], j};
}
sort(kol.begin(), kol.end());
for(int j=0; j<C; j++){
dist[v][i][j]=1e9;
for(int k=0; k<C; k++){
dist[v][i][j]=min(dist[v][i][j], kol[k].first+dist[r][kol[k].second][j]);
if(kol[k].first+mini[j]>=dist[v][i][j])break;
}
}
}
}
/*cerr<<"\n";
cerr<<v<<"a\n";
cerr<<l<<" "<<r<<"\n";
for(int i=0; i<C; i++){
for(int j=0; j<C; j++){
cerr<<dist[v][i][j]<<" \n"[j==C-1];
}
}
cerr<<"\n";*/
}
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*K<R-1; i++){
blo++;
}
while(__builtin_popcount(blo)>1)blo++;
for(int i=0; i*K<R-1; i++){
pocz[i]=i*K;
kon[i]=min((i+1)*K-1, R-2);
update(i);
czy[i+blo]=1;
}
for(int i=blo-1; i>0; i--){
czy[i]=(czy[i+i]|czy[i+i+1]);
lacz(i);
}
get_res();
/*for(int i=0; i<C; i++){
for(int j=0; j<C; j++){
cerr<<i<<" "<<j<<" "<<escape(i, j)<<"\n";
}
}*/
}
void changeH(int P, int Q, int W) {
H[P][Q]=W;
if(P!=R-1){
update(P/K);
int v=P/K+blo;
v/=2;
while(v){
lacz(v);
v/=2;
}
}
get_res();
/*for(int i=0; i<C; i++){
for(int j=0; j<C; j++){
cerr<<i<<" "<<j<<" "<<escape(i, j)<<"\n";
}
}*/
}
void changeV(int P, int Q, int W) {
V[P][Q]=W;
update(P/K);
int v=P/K+blo;
v/=2;
while(v){
lacz(v);
v/=2;
}
get_res();
/*for(int i=0; i<C; i++){
for(int j=0; j<C; j++){
cerr<<i<<" "<<j<<" "<<escape(i, j)<<"\n";
}
}*/
}
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 |
12532 KB |
Output is correct |
2 |
Correct |
6 ms |
12500 KB |
Output is correct |
3 |
Correct |
62 ms |
14124 KB |
Output is correct |
4 |
Correct |
6 ms |
12500 KB |
Output is correct |
5 |
Correct |
8 ms |
12576 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
69 ms |
1384 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
462 ms |
988 KB |
Output is correct |
2 |
Correct |
630 ms |
992 KB |
Output is correct |
3 |
Correct |
635 ms |
988 KB |
Output is correct |
4 |
Correct |
654 ms |
1108 KB |
Output is correct |
5 |
Correct |
700 ms |
980 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
3195 ms |
1004 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16468 KB |
Output is correct |
2 |
Correct |
8 ms |
16468 KB |
Output is correct |
3 |
Correct |
8 ms |
16560 KB |
Output is correct |
4 |
Correct |
40 ms |
17240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
458 ms |
980 KB |
Output is correct |
2 |
Correct |
626 ms |
1004 KB |
Output is correct |
3 |
Correct |
634 ms |
1100 KB |
Output is correct |
4 |
Correct |
655 ms |
988 KB |
Output is correct |
5 |
Correct |
703 ms |
980 KB |
Output is correct |
6 |
Correct |
9 ms |
16468 KB |
Output is correct |
7 |
Correct |
8 ms |
16468 KB |
Output is correct |
8 |
Correct |
8 ms |
16468 KB |
Output is correct |
9 |
Correct |
36 ms |
17324 KB |
Output is correct |
10 |
Correct |
6 ms |
12500 KB |
Output is correct |
11 |
Correct |
8 ms |
12540 KB |
Output is correct |
12 |
Correct |
60 ms |
14048 KB |
Output is correct |
13 |
Correct |
5 ms |
12500 KB |
Output is correct |
14 |
Correct |
6 ms |
12500 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
55 ms |
1352 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
3212 ms |
1008 KB |
Output is correct |
28 |
Correct |
4054 ms |
26168 KB |
Output is correct |
29 |
Correct |
5107 ms |
22024 KB |
Output is correct |
30 |
Correct |
5382 ms |
22012 KB |
Output is correct |
31 |
Correct |
4181 ms |
27400 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
462 ms |
996 KB |
Output is correct |
2 |
Correct |
624 ms |
988 KB |
Output is correct |
3 |
Correct |
635 ms |
988 KB |
Output is correct |
4 |
Correct |
658 ms |
1100 KB |
Output is correct |
5 |
Correct |
702 ms |
992 KB |
Output is correct |
6 |
Correct |
8 ms |
16468 KB |
Output is correct |
7 |
Correct |
8 ms |
16568 KB |
Output is correct |
8 |
Correct |
8 ms |
16452 KB |
Output is correct |
9 |
Correct |
37 ms |
17232 KB |
Output is correct |
10 |
Correct |
6 ms |
12500 KB |
Output is correct |
11 |
Correct |
6 ms |
12500 KB |
Output is correct |
12 |
Correct |
61 ms |
14156 KB |
Output is correct |
13 |
Correct |
6 ms |
12500 KB |
Output is correct |
14 |
Correct |
6 ms |
12500 KB |
Output is correct |
15 |
Correct |
2275 ms |
34932 KB |
Output is correct |
16 |
Execution timed out |
20064 ms |
35984 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |