Submission #1068914

#TimeUsernameProblemLanguageResultExecution timeMemory
1068914sleepntsheepWombats (IOI13_wombats)C++17
Compilation error
0 ms0 KiB
#pragma GCC optimize("O3,unroll-loops") #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> using namespace std; #include "wombats.h" #ifndef ROW #define ROW 5000 #endif #define COL 200 /* 256 Mb memory - 64 Million Ints - one matrix is 200x200 -> max 1600 block + segtree Memory - 200^2 * 2 * ceil(5000 / B) Time Per update - [ 200 * 200 * B + lg[ceil(5000 / B)] * 200 * 200] there are 500 updates Time for Init - [ 200 * 200 * B * ceil(5000 / B) + 200 * 200 * ceil(5000 / B) ] = [ 200 * 200 * 5000 + 200 * 200 * ceil(5000 / B) ] 1600 matrix - maybe B = 8, [5000 / B] = 625 */ constexpr int B = 20; int nb; int r, c, h[5009][COL], v[5009][COL]; int L[9999], R[9999], a[1024][COL][COL]; void Unit(int blk) { for (int ii = 0; ii < c; ++ii) { static int dp[2][COL]; /* find answer for (V1, V2) where V1 = ii */ memset(dp[0], 63, sizeof dp[0]); dp[0][ii] = 0; int I = 0; for (int i = L[blk]; i <= R[blk]; ++i, I ^= 1) { if (i < r) { int pre = 1e9, suf = 1e9; for (int j = 0; j < c; ++j) { pre = min(pre, dp[I][j] - h[i][j]); dp[I][j] = min(dp[I][j], h[i][j] + pre); } for (int j = c - 1; j >= 0; --j) { suf = min(suf, dp[I][j] + h[i][j]); dp[I][j] = min(dp[I][j], suf - h[i][j]); } } for (int j = 0; j < c; ++j) dp[!I][j] = dp[I][j] + v[i][j]; } for (int jj = 0; jj < c; ++jj) a[blk + nb][ii][jj] = dp[I][jj]; } } void merg(int v) { for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) a[v][i][j] = 1e9; for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) for (int k = 0; k < c; ++k) a[v][i][j] = min(a[v][i][j], a[2 * v][i][k] + a[2 * v + 1][k][j]); } void init(int R, int C, int H[ROW][200], int V[ROW][200]) { r = R, c = C; for (int i = 0; i + 1 < r; ++i) for (int j = 0; j < c; ++j) v[i][j] = V[i][j]; for (int i = 0 ; i < r; ++i) for (int j = 0; j + 1 < c; ++j) h[i][j + 1] = H[i][j] + h[i][j]; nb = (r + B - 1) / B; while ((nb - 1) & nb) ++nb; for (int i = 0; i < nb; ++i) { L[i] = i * B; ::R[i] = min(r - 1, i * B + B - 1); Unit(i); } for (int i = nb; --i; ) merg(i); } void update(int p) { Unit(p); for (p += nb; p /= 2; ) merg(p); } void changeH(int P, int Q, int W) { int dl = W - h[P][Q + 1] + h[P][Q]; for (int j = Q + 1; j < c; ++j) h[P][j] += dl; update(P / B); } void changeV(int P, int Q, int W) { v[P][Q] = W; update(P / B); } int escape(int V1, int V2) { return a[1][V1][V2]; } #pragma GCC optimize("O3,unroll-loops") #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> using namespace std; #include "wombats.h" #ifndef ROW #define ROW 5000 #endif #define COL 200 /* 256 Mb memory - 64 Million Ints - one matrix is 200x200 -> max 1600 block + segtree Memory - 200^2 * 2 * ceil(5000 / B) Time Per update - [ 200 * 200 * B + lg[ceil(5000 / B)] * 200 * 200] there are 500 updates Time for Init - [ 200 * 200 * B * ceil(5000 / B) + 200 * 200 * ceil(5000 / B) ] = [ 200 * 200 * 5000 + 200 * 200 * ceil(5000 / B) ] 1600 matrix - maybe B = 8, [5000 / B] = 625 */ constexpr int B = 20; int nb; int r, c, h[5009][COL], v[5009][COL]; int L[9999], R[9999], a[1024][COL][COL]; void Unit(int blk) { for (int ii = 0; ii < c; ++ii) { static int dp[2][COL]; /* find answer for (V1, V2) where V1 = ii */ memset(dp[0], 63, sizeof dp[0]); dp[0][ii] = 0; int I = 0; for (int i = L[blk]; i <= R[blk]; ++i, I ^= 1) { if (i < r) { int pre = 1e9, suf = 1e9; for (int j = 0; j < c; ++j) { pre = min(pre, dp[I][j] - h[i][j]); dp[I][j] = min(dp[I][j], h[i][j] + pre); } for (int j = c - 1; j >= 0; --j) { suf = min(suf, dp[I][j] + h[i][j]); dp[I][j] = min(dp[I][j], suf - h[i][j]); } } for (int j = 0; j < c; ++j) dp[!I][j] = dp[I][j] + v[i][j]; } for (int jj = 0; jj < c; ++jj) a[blk + nb][ii][jj] = dp[I][jj]; } } void merg(int v) { for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) a[v][i][j] = 1e9; for (int i = 0; i < c; ++i) for (int j = 0; j < c; ++j) for (int k = 0; k < c; ++k) a[v][i][k] = min(a[v][i][k], a[2 * v][i][j] + a[2 * v + 1][j][k]); } void init(int R, int C, int H[ROW][200], int V[ROW][200]) { r = R, c = C; for (int i = 0; i + 1 < r; ++i) for (int j = 0; j < c; ++j) v[i][j] = V[i][j]; for (int i = 0 ; i < r; ++i) for (int j = 0; j + 1 < c; ++j) h[i][j + 1] = H[i][j] + h[i][j]; nb = (r + B - 1) / B; while ((nb - 1) & nb) ++nb; for (int i = 0; i < nb; ++i) { L[i] = i * B; ::R[i] = min(r - 1, i * B + B - 1); Unit(i); } for (int i = nb; --i; ) merg(i); } void update(int p) { Unit(p); for (p += nb; p /= 2; ) merg(p); } void changeH(int P, int Q, int W) { int dl = W - h[P][Q + 1] + h[P][Q]; for (int j = Q + 1; j < c; ++j) h[P][j] += dl; update(P / B); } void changeV(int P, int Q, int W) { v[P][Q] = W; update(P / B); } int escape(int V1, int V2) { return a[1][V1][V2]; }

Compilation message (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;
      |      ^~~
wombats.cpp:126:15: error: redefinition of 'constexpr const int B'
  126 | constexpr int B = 20;
      |               ^
wombats.cpp:27:15: note: 'constexpr const int B' previously defined here
   27 | constexpr int B = 20;
      |               ^
wombats.cpp:127:5: error: redefinition of 'int nb'
  127 | int nb;
      |     ^~
wombats.cpp:28:5: note: 'int nb' previously declared here
   28 | int nb;
      |     ^~
wombats.cpp:129:5: error: redefinition of 'int r'
  129 | int r, c, h[5009][COL], v[5009][COL];
      |     ^
wombats.cpp:30:5: note: 'int r' previously declared here
   30 | int r, c, h[5009][COL], v[5009][COL];
      |     ^
wombats.cpp:129:8: error: redefinition of 'int c'
  129 | int r, c, h[5009][COL], v[5009][COL];
      |        ^
wombats.cpp:30:8: note: 'int c' previously declared here
   30 | int r, c, h[5009][COL], v[5009][COL];
      |        ^
wombats.cpp:129:11: error: redefinition of 'int h [5009][200]'
  129 | int r, c, h[5009][COL], v[5009][COL];
      |           ^
wombats.cpp:30:11: note: 'int h [5009][200]' previously declared here
   30 | int r, c, h[5009][COL], v[5009][COL];
      |           ^
wombats.cpp:129:25: error: redefinition of 'int v [5009][200]'
  129 | int r, c, h[5009][COL], v[5009][COL];
      |                         ^
wombats.cpp:30:25: note: 'int v [5009][200]' previously declared here
   30 | int r, c, h[5009][COL], v[5009][COL];
      |                         ^
wombats.cpp:131:5: error: redefinition of 'int L [9999]'
  131 | int L[9999], R[9999], a[1024][COL][COL];
      |     ^
wombats.cpp:32:5: note: 'int L [9999]' previously declared here
   32 | int L[9999], R[9999], a[1024][COL][COL];
      |     ^
wombats.cpp:131:14: error: redefinition of 'int R [9999]'
  131 | int L[9999], R[9999], a[1024][COL][COL];
      |              ^
wombats.cpp:32:14: note: 'int R [9999]' previously declared here
   32 | int L[9999], R[9999], a[1024][COL][COL];
      |              ^
wombats.cpp:131:23: error: redefinition of 'int a [1024][200][200]'
  131 | int L[9999], R[9999], a[1024][COL][COL];
      |                       ^
wombats.cpp:32:23: note: 'int a [1024][200][200]' previously declared here
   32 | int L[9999], R[9999], a[1024][COL][COL];
      |                       ^
wombats.cpp:133:6: error: redefinition of 'void Unit(int)'
  133 | void Unit(int blk) {
      |      ^~~~
wombats.cpp:34:6: note: 'void Unit(int)' previously defined here
   34 | void Unit(int blk) {
      |      ^~~~
wombats.cpp:159:6: error: redefinition of 'void merg(int)'
  159 | void merg(int v) {
      |      ^~~~
wombats.cpp:60:6: note: 'void merg(int)' previously defined here
   60 | void merg(int v) {
      |      ^~~~
wombats.cpp:166:6: error: redefinition of 'void init(int, int, int (*)[200], int (*)[200])'
  166 | void init(int R, int C, int H[ROW][200], int V[ROW][200]) {
      |      ^~~~
wombats.cpp:67:6: note: 'void init(int, int, int (*)[200], int (*)[200])' previously defined here
   67 | void init(int R, int C, int H[ROW][200], int V[ROW][200]) {
      |      ^~~~
wombats.cpp:182:6: error: redefinition of 'void update(int)'
  182 | void update(int p) {
      |      ^~~~~~
wombats.cpp:83:6: note: 'void update(int)' previously defined here
   83 | void update(int p) {
      |      ^~~~~~
wombats.cpp:187:6: error: redefinition of 'void changeH(int, int, int)'
  187 | void changeH(int P, int Q, int W) {
      |      ^~~~~~~
wombats.cpp:88:6: note: 'void changeH(int, int, int)' previously defined here
   88 | void changeH(int P, int Q, int W) {
      |      ^~~~~~~
wombats.cpp:193:6: error: redefinition of 'void changeV(int, int, int)'
  193 | void changeV(int P, int Q, int W) {
      |      ^~~~~~~
wombats.cpp:94:6: note: 'void changeV(int, int, int)' previously defined here
   94 | void changeV(int P, int Q, int W) {
      |      ^~~~~~~
wombats.cpp:198:5: error: redefinition of 'int escape(int, int)'
  198 | int escape(int V1, int V2) { return a[1][V1][V2]; }
      |     ^~~~~~
wombats.cpp:99:5: note: 'int escape(int, int)' previously defined here
   99 | int escape(int V1, int V2) { return a[1][V1][V2]; }
      |     ^~~~~~