#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
#ifdef __cplusplus
extern "C" {
#endif
void init(int R, int C, int H[5000][200], int V[5000][200]);
void changeH(int P, int Q, int W);
void changeV(int P, int Q, int W);
int escape(int V1, int V2);
#ifdef __cplusplus
}
#endif
template <typename T, size_t N>
ostream& operator<<(ostream& out, const array<T, N>& arr) {
out << "{";
for (size_t i = 0; i < N; i++) {
out << arr[i];
if (i + 1 < N) {
out << ", ";
}
}
return out << "}";
}
const int maxn = 5000, maxm = 200, bsize = 320, maxt = 16;
// const int maxn = 32, maxm = 10, bsize = 2, maxt = 16;
static_assert((maxn - 1) / bsize < maxt);
template <size_t N, size_t M>
using mat = array<array<int, M>, N>;
template <size_t A, size_t B, size_t C>
mat<A, C> mul(const mat<A, B>& x, const mat<B, C>& y) {
static_assert(C % 8 == 0);
mat<A, C> ans;
for (auto& a : ans) {
a.fill(1e9);
}
for (size_t i = 0; i < A; i++) {
for (size_t j = 0; j < B; j++) {
for (size_t k = 0; k < C; k++) {
ans[i][k] = min(ans[i][k], x[i][j] + y[j][k]);
}
}
}
return ans;
}
int n, m, harr[5000][200], varr[5000][200];
mat<maxm, maxm> v[maxt * 2];
mat<maxm, maxm> solve(int l, int r) {
mat<maxm, maxm> ans {};
for (int i = 0; i < maxm; i++) {
ans[i].fill(1e9);
ans[i][i] = 0;
}
for (int i = 0; i < m; i++) {
auto& dp = ans[i];
for (int j = l; j < r; j++) {
array<int, maxm> ndp;
ndp.fill(1e9);
int psum[m + 1];
psum[0] = 0;
partial_sum(harr[j], harr[j] + m, psum + 1);
int ans = 1e9;
for (int k = 0; k < m; k++) {
ans = min(ans, dp[k] - psum[k]);
ndp[k] = min(ndp[k], ans + varr[j][k] + psum[k]);
}
ans = 1e9;
for (int k = m - 1; k >= 0; k--) {
ans = min(ans, dp[k] + psum[k]);
ndp[k] = min(ndp[k], ans + varr[j][k] - psum[k]);
}
swap(dp, ndp);
}
}
return ans;
}
void update_leaf(int ind) {
int x = ind - maxt;
v[ind] = solve(x * bsize, min(n, (x + 1) * bsize));
}
void maintain(int o) {
v[o] = mul(v[o * 2], v[o * 2 + 1]);
}
void init(int _n, int _m, int _harr[5000][200], int _varr[5000][200]) {
n = _n;
m = _m;
for (int i = 0; i < n; i++) {
copy(_harr[i], _harr[i] + m, harr[i]);
copy(_varr[i], _varr[i] + m, varr[i]);
}
for (int i = maxt; i < 2 * maxt; i++) {
update_leaf(i);
}
for (int i = maxt - 1; i; i--) {
maintain(i);
}
}
void update(int ind) {
static int cnt = 0;
assert(++cnt <= 500);
ind /= bsize;
ind += maxt;
update_leaf(ind);
while (true) {
ind >>= 1;
if (!ind) {
break;
}
maintain(ind);
}
}
void changeH(int x, int y, int w) {
harr[x][y] = w;
update(x);
}
void changeV(int x, int y, int w) {
varr[x][y] = w;
update(x);
}
int escape(int a, int b) {
return v[1][a][b];
}
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 |
2089 ms |
17324 KB |
Output is correct |
2 |
Correct |
2049 ms |
17196 KB |
Output is correct |
3 |
Correct |
2136 ms |
18732 KB |
Output is correct |
4 |
Correct |
2009 ms |
17192 KB |
Output is correct |
5 |
Correct |
2105 ms |
17192 KB |
Output is correct |
6 |
Correct |
20 ms |
5368 KB |
Output is correct |
7 |
Correct |
18 ms |
5408 KB |
Output is correct |
8 |
Correct |
21 ms |
5460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
5380 KB |
Output is correct |
2 |
Correct |
16 ms |
5460 KB |
Output is correct |
3 |
Correct |
17 ms |
5400 KB |
Output is correct |
4 |
Correct |
17 ms |
5508 KB |
Output is correct |
5 |
Correct |
16 ms |
5440 KB |
Output is correct |
6 |
Correct |
19 ms |
5544 KB |
Output is correct |
7 |
Correct |
22 ms |
5456 KB |
Output is correct |
8 |
Correct |
17 ms |
5460 KB |
Output is correct |
9 |
Correct |
17 ms |
5492 KB |
Output is correct |
10 |
Correct |
17 ms |
5524 KB |
Output is correct |
11 |
Correct |
80 ms |
6516 KB |
Output is correct |
12 |
Correct |
17 ms |
5460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1882 ms |
5780 KB |
Output is correct |
2 |
Correct |
2053 ms |
5780 KB |
Output is correct |
3 |
Correct |
1950 ms |
5784 KB |
Output is correct |
4 |
Correct |
1932 ms |
5788 KB |
Output is correct |
5 |
Correct |
1923 ms |
5780 KB |
Output is correct |
6 |
Correct |
24 ms |
5460 KB |
Output is correct |
7 |
Correct |
19 ms |
5372 KB |
Output is correct |
8 |
Correct |
17 ms |
5432 KB |
Output is correct |
9 |
Correct |
9577 ms |
5888 KB |
Output is correct |
10 |
Correct |
23 ms |
5504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2331 ms |
21136 KB |
Output is correct |
2 |
Correct |
2258 ms |
21192 KB |
Output is correct |
3 |
Correct |
2212 ms |
21100 KB |
Output is correct |
4 |
Correct |
2395 ms |
22012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1901 ms |
5780 KB |
Output is correct |
2 |
Correct |
1912 ms |
5888 KB |
Output is correct |
3 |
Correct |
1932 ms |
5784 KB |
Output is correct |
4 |
Correct |
1942 ms |
5784 KB |
Output is correct |
5 |
Correct |
1932 ms |
5780 KB |
Output is correct |
6 |
Correct |
2187 ms |
21100 KB |
Output is correct |
7 |
Correct |
2258 ms |
21264 KB |
Output is correct |
8 |
Correct |
2289 ms |
21104 KB |
Output is correct |
9 |
Correct |
2404 ms |
22016 KB |
Output is correct |
10 |
Correct |
2032 ms |
17216 KB |
Output is correct |
11 |
Correct |
2094 ms |
17208 KB |
Output is correct |
12 |
Correct |
2111 ms |
18732 KB |
Output is correct |
13 |
Correct |
2036 ms |
17196 KB |
Output is correct |
14 |
Correct |
2036 ms |
17192 KB |
Output is correct |
15 |
Correct |
22 ms |
5460 KB |
Output is correct |
16 |
Correct |
23 ms |
5400 KB |
Output is correct |
17 |
Correct |
17 ms |
5396 KB |
Output is correct |
18 |
Correct |
19 ms |
5420 KB |
Output is correct |
19 |
Correct |
17 ms |
5460 KB |
Output is correct |
20 |
Correct |
17 ms |
5536 KB |
Output is correct |
21 |
Correct |
20 ms |
5452 KB |
Output is correct |
22 |
Correct |
17 ms |
5544 KB |
Output is correct |
23 |
Correct |
19 ms |
5492 KB |
Output is correct |
24 |
Correct |
25 ms |
5468 KB |
Output is correct |
25 |
Correct |
90 ms |
6444 KB |
Output is correct |
26 |
Correct |
17 ms |
5448 KB |
Output is correct |
27 |
Correct |
9329 ms |
5756 KB |
Output is correct |
28 |
Execution timed out |
20085 ms |
21268 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1912 ms |
5780 KB |
Output is correct |
2 |
Correct |
1841 ms |
5780 KB |
Output is correct |
3 |
Correct |
1898 ms |
5908 KB |
Output is correct |
4 |
Correct |
1910 ms |
5780 KB |
Output is correct |
5 |
Correct |
1924 ms |
5784 KB |
Output is correct |
6 |
Correct |
2291 ms |
21228 KB |
Output is correct |
7 |
Correct |
2263 ms |
21108 KB |
Output is correct |
8 |
Correct |
2312 ms |
21100 KB |
Output is correct |
9 |
Correct |
2334 ms |
21868 KB |
Output is correct |
10 |
Correct |
2017 ms |
17200 KB |
Output is correct |
11 |
Correct |
2015 ms |
17252 KB |
Output is correct |
12 |
Correct |
2195 ms |
18728 KB |
Output is correct |
13 |
Correct |
2089 ms |
17196 KB |
Output is correct |
14 |
Correct |
2124 ms |
17188 KB |
Output is correct |
15 |
Correct |
2434 ms |
21020 KB |
Output is correct |
16 |
Execution timed out |
20083 ms |
21464 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |