답안 #378013

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

const int INF = 0x3f3f3f3f;

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

vector< vector<int> > calc(int x) {
  vector< vector<int> > cost(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]);
      cost[i][j] = min(cost[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]);
      cost[i][j] = min(cost[i][j], mn - pre[1][j]);
    }
  }
  return move(cost);
}

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);
}

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

node *build(int l, int r) {
  if (l + 1 == r) return new node{l, r, calc(l), 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(x);
    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];
  root = build(0, r - 1);
}

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

void changeV(int P, int Q, int W) {
  v[P][Q] = W;
  update(root, 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:25:14: warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move]
   25 |   return move(cost);
      |          ~~~~^~~~~~
wombats.cpp:25: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:41:14: warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move]
   41 |   return move(ans);
      |          ~~~~^~~~~
wombats.cpp:41:14: note: remove 'std::move' call
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6016 KB Output is correct
2 Correct 8 ms 5868 KB Output is correct
3 Correct 119 ms 8684 KB Output is correct
4 Correct 8 ms 5868 KB Output is correct
5 Correct 8 ms 5868 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
# 결과 실행 시간 메모리 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 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 82 ms 2796 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 9196 KB Output is correct
2 Correct 111 ms 9068 KB Output is correct
3 Correct 190 ms 9324 KB Output is correct
4 Correct 112 ms 9324 KB Output is correct
5 Correct 175 ms 9196 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 657 ms 9580 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 10604 KB Output is correct
2 Correct 13 ms 10604 KB Output is correct
3 Correct 21 ms 10604 KB Output is correct
4 Correct 54 ms 12012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 194 ms 9324 KB Output is correct
2 Correct 91 ms 9068 KB Output is correct
3 Correct 198 ms 9452 KB Output is correct
4 Correct 112 ms 9344 KB Output is correct
5 Correct 146 ms 9196 KB Output is correct
6 Correct 14 ms 10604 KB Output is correct
7 Correct 13 ms 10604 KB Output is correct
8 Correct 20 ms 10604 KB Output is correct
9 Correct 56 ms 12012 KB Output is correct
10 Correct 10 ms 5868 KB Output is correct
11 Correct 8 ms 5868 KB Output is correct
12 Correct 87 ms 8812 KB Output is correct
13 Correct 8 ms 5868 KB Output is correct
14 Correct 8 ms 5868 KB Output is correct
15 Correct 1 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 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 82 ms 2924 KB Output is correct
26 Correct 1 ms 640 KB Output is correct
27 Correct 662 ms 9368 KB Output is correct
28 Runtime error 768 ms 262148 KB Execution killed with signal 9
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 154 ms 9196 KB Output is correct
2 Correct 89 ms 9068 KB Output is correct
3 Correct 217 ms 9452 KB Output is correct
4 Correct 111 ms 9324 KB Output is correct
5 Correct 151 ms 9324 KB Output is correct
6 Correct 16 ms 10604 KB Output is correct
7 Correct 14 ms 10604 KB Output is correct
8 Correct 14 ms 10732 KB Output is correct
9 Correct 55 ms 12012 KB Output is correct
10 Correct 8 ms 5868 KB Output is correct
11 Correct 8 ms 5868 KB Output is correct
12 Correct 92 ms 8684 KB Output is correct
13 Correct 10 ms 6124 KB Output is correct
14 Correct 11 ms 6016 KB Output is correct
15 Runtime error 856 ms 262148 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -