답안 #378017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378017 2021-03-15T18:28:00 Z WLZ 웜뱃 (IOI13_wombats) C++14
100 / 100
12374 ms 197100 KB
#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;

const int INF = 0x3f3f3f3f;

int r, c;
vector< vector<int> > h, v;
vector<int> range;

vector< vector<int> > calc(int x) {
  vector< vector<int> > ans(c, vector<int>(c, INF)), pre(2, vector<int>(c, 0));
  for (int i = 0; i < 2; i++) for (int j = 1; j < c; j++) pre[i][j] = pre[i][j - 1] + h[x + i][j - 1];
  for (int i = 0; i < c; i++) {
    int mx = -INF;
    for (int j = 0; j < c; j++) {
      mx = max(mx, pre[1][j] - abs(pre[0][i] - pre[0][j]) - v[x][j]);
      ans[i][j] = min(ans[i][j], pre[1][j] - mx);
    }
    int mn = INF;
    for (int j = c - 1; j >= 0; j--) {
      mn = min(mn, abs(pre[0][i] - pre[0][j]) + v[x][j] + pre[1][j]);
      ans[i][j] = min(ans[i][j], mn - pre[1][j]);
    }
  }
  return move(ans);
}

vector< vector<int> > combine(const vector< vector<int> > &a, const vector< vector<int> > &b) {
  vector< vector<int> > ans(c, vector<int>(c, INF)), best(c, vector<int>(c, -1));
  for (int i = 0; i < c; i++) {
    for (int j = c - 1; j >= 0; j--) {
      int l = i == 0 ? 0 : best[i - 1][j], r = j == c - 1 ? c - 1 : best[i][j + 1];
      for (int k = l; k <= r; k++) {
        if (a[i][k] + b[k][j] < ans[i][j]) {
          ans[i][j] = a[i][k] + b[k][j];
          best[i][j] = k;
        }
      }
    }
  }
  return move(ans);
}

vector< vector<int> > calc(int l, int r) {
  vector< vector<int> > ans = calc(l);
  for (int i = l + 1; i < r; i++) ans = combine(ans, calc(i));
  return move(ans);
}

struct node {
  int l, r;
  vector< vector<int> > cost;
  node *left, *right;
} *root;

node *build(int l, int r) {
  if (l + 10 >= r) {
    for (int i = l; i < r; i++) range[i] = l;
    return new node{l, r, calc(l, r), nullptr, nullptr};
  }
  node *left = build(l, (l + r) / 2), *right = build((l + r) / 2, r);
  return new node{l, r, combine(left->cost, right->cost), left, right};
}

void update(node *cur, int x) {
  if (cur->left == nullptr) {
    assert(cur->l == x);
    cur->cost = calc(cur->l, cur->r);
    return;
  }
  if (cur->right->l <= x) update(cur->right, x);
  else update(cur->left, x);
  cur->cost = combine(cur->left->cost, cur->right->cost);
}

void init(int R, int C, int H[5000][200], int V[5000][200]) {
  r = R, c = C;
  h.assign(r, vector<int>(c - 1));
  for (int i = 0; i < r; i++) for (int j = 0; j < c - 1; j++) h[i][j] = H[i][j];
  v.assign(r - 1, vector<int>(c));
  for (int i = 0; i < r - 1; i++) for (int j = 0; j < c; j++) v[i][j] = V[i][j];
  range.resize(r - 1);
  root = build(0, r - 1);
}

void changeH(int P, int Q, int W) {
  h[P][Q] = W;
  if (P > 0) update(root, range[P - 1]);
  if (P < r - 1) update(root, range[P]);
}

void changeV(int P, int Q, int W) {
  v[P][Q] = W;
  update(root, range[P]);
}

int escape(int V1, int V2) {
  return root->cost[V1][V2];
}

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 'std::vector<std::vector<int> > calc(int)':
wombats.cpp:26:14: warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move]
   26 |   return move(ans);
      |          ~~~~^~~~~
wombats.cpp:26:14: note: remove 'std::move' call
wombats.cpp: In function 'std::vector<std::vector<int> > combine(const std::vector<std::vector<int> >&, const std::vector<std::vector<int> >&)':
wombats.cpp:42:14: warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move]
   42 |   return move(ans);
      |          ~~~~^~~~~
wombats.cpp:42:14: note: remove 'std::move' call
wombats.cpp: In function 'std::vector<std::vector<int> > calc(int, int)':
wombats.cpp:48:14: warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move]
   48 |   return move(ans);
      |          ~~~~^~~~~
wombats.cpp:48:14: note: remove 'std::move' call
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4716 KB Output is correct
2 Correct 8 ms 4716 KB Output is correct
3 Correct 87 ms 6508 KB Output is correct
4 Correct 8 ms 4716 KB Output is correct
5 Correct 8 ms 4716 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 90 ms 1388 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 2304 KB Output is correct
2 Correct 143 ms 2028 KB Output is correct
3 Correct 331 ms 2284 KB Output is correct
4 Correct 179 ms 2284 KB Output is correct
5 Correct 235 ms 2156 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1165 ms 2156 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 8940 KB Output is correct
2 Correct 14 ms 8940 KB Output is correct
3 Correct 15 ms 8940 KB Output is correct
4 Correct 54 ms 9708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 253 ms 2152 KB Output is correct
2 Correct 144 ms 2156 KB Output is correct
3 Correct 349 ms 2540 KB Output is correct
4 Correct 189 ms 2120 KB Output is correct
5 Correct 237 ms 2028 KB Output is correct
6 Correct 15 ms 8940 KB Output is correct
7 Correct 14 ms 8940 KB Output is correct
8 Correct 15 ms 8940 KB Output is correct
9 Correct 62 ms 9708 KB Output is correct
10 Correct 8 ms 4716 KB Output is correct
11 Correct 8 ms 4716 KB Output is correct
12 Correct 105 ms 6380 KB Output is correct
13 Correct 8 ms 4716 KB Output is correct
14 Correct 8 ms 4716 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 89 ms 1388 KB Output is correct
26 Correct 1 ms 512 KB Output is correct
27 Correct 1139 ms 2284 KB Output is correct
28 Correct 3265 ms 61260 KB Output is correct
29 Correct 2766 ms 58860 KB Output is correct
30 Correct 3008 ms 58700 KB Output is correct
31 Correct 3008 ms 62956 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 249 ms 2172 KB Output is correct
2 Correct 150 ms 2028 KB Output is correct
3 Correct 341 ms 2156 KB Output is correct
4 Correct 179 ms 2156 KB Output is correct
5 Correct 236 ms 2156 KB Output is correct
6 Correct 15 ms 8940 KB Output is correct
7 Correct 13 ms 8940 KB Output is correct
8 Correct 15 ms 9088 KB Output is correct
9 Correct 55 ms 9708 KB Output is correct
10 Correct 8 ms 4716 KB Output is correct
11 Correct 8 ms 4716 KB Output is correct
12 Correct 86 ms 6452 KB Output is correct
13 Correct 8 ms 4716 KB Output is correct
14 Correct 8 ms 4716 KB Output is correct
15 Correct 3568 ms 195564 KB Output is correct
16 Correct 12177 ms 197100 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 80 ms 2796 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1128 ms 2232 KB Output is correct
30 Correct 3222 ms 61256 KB Output is correct
31 Correct 12000 ms 194432 KB Output is correct
32 Correct 12374 ms 194756 KB Output is correct
33 Correct 2954 ms 59036 KB Output is correct
34 Correct 10303 ms 191056 KB Output is correct
35 Correct 2890 ms 58872 KB Output is correct
36 Correct 10655 ms 191100 KB Output is correct
37 Correct 2932 ms 62956 KB Output is correct
38 Correct 11142 ms 195364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 11047 ms 191140 KB Output is correct