이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
const int len_n = 5005, len_m = 205, inf = 1e9+10;
int hor[len_n][len_m], ver[len_n][len_m], n, m, k;
struct{
struct node{
int to[len_m][len_m];
node(){
for (int a = 0; a < m; a++)
for (int b = 0; b < m; b++)
to[a][b] = inf; // check this
}
node(int i){
for (int a = 0; a < m; a++)
for (int b = 0; b < m; b++)
to[a][b] = inf; // check this
for (int a = 0; a < m; a++){
for (int b = a, sum = 0; b < m; b++){
//printf("a = %d, b = %d, sum = %d\n", a, b, sum);
for (int c = a, cur = sum; c <= b; c++){
//printf("c = %d, cur = %d\n", c, cur);
to[a][b] = min(to[a][b], cur+ver[i][c]);
cur += hor[i][c]-hor[i+1][c];
}
sum += hor[i+1][b];
}
}
for (int a = 0; a < m; a++){
for (int b = a, sum = 0; b >= 0; b--){
//printf("a = %d, b = %d, sum = %d\n", a, b, sum);
for (int c = a, cur = sum; c >= b; c--){
//printf("c = %d, cur = %d\n", c, cur);
to[a][b] = min(to[a][b], cur+ver[i][c]);
if (c > 0)
cur += hor[i][c-1]-hor[i+1][c-1];
}
if (b > 0)
sum += hor[i+1][b-1];
}
}
if (0){
printf("-------------------------------------------\n");
printf("just constructed %d-th leaf\n", i);
for (int a = 0; a < m; a++){
for (int b = 0; b < m; b++)
printf("%d ", to[a][b]);
printf("\n");
}
printf("-------------------------------------------\n");
}
}
};
node buck[75], root;
node join(node fir, node sec){
node res;
for (int a = 0; a < m; a++)
for (int b = 0; b < m; b++)
for (int c = 0; c < m; c++)
res.to[a][b] = min(res.to[a][b], fir.to[a][c]+sec.to[c][b]);
return res;
}
void upd_buck(int b){
int st = b*k, en = min(n-1, (b+1)*k);
buck[b] = node(st);
for (int i = st+1; i < en; i++)
buck[b] = join(buck[b], node(i));
}
void upd_root(){
root = buck[0];
for (int b = 1; b*k < n-1; b++)
root = join(root, buck[b]);
}
int ask(int a, int b){
return root.to[a][b];
}
} data;
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++)
for (int j = 0; j < m-1; j++)
hor[i][j] = H[i][j];
for (int i = 0; i < n-1; i++)
for (int j = 0; j < m; j++)
ver[i][j] = V[i][j];
k = 70; //sqrt(n);
for (int b = 0; k*b < n-1; b++)
data.upd_buck(b);
data.upd_root();
}
void changeH(int P, int Q, int W) {
hor[P][Q] = W;
if (P > 0)
data.upd_buck((P-1)/k);
if (P < n-1)
data.upd_buck(P/k);
data.upd_root();
}
void changeV(int P, int Q, int W) {
ver[P][Q] = W;
data.upd_buck(P/k);
data.upd_root();
}
int escape(int V1, int V2) {
return data.ask(V1, V2);
}
컴파일 시 표준 에러 (stderr) 메시지
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
15 | int res;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |