답안 #24370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
24370 2017-06-06T05:54:23 Z jiaqiyang 유괴 2 (JOI17_abduction2) C++14
44 / 100
273 ms 43752 KB
#include <cstdio>
#include <cstring>
#include <map>
#include <tuple>

const int N = 50000 + 10;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int n, m, a[N], b[N];
int f[4][20][N];

int init() {
  int q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
  memset(f, 0x3f, sizeof f);
  for (int i = 1; i <= n; ++i) f[0][0][i] = f[2][0][i] = a[i];
  for (int i = 1; i <= m; ++i) f[1][0][i] = f[3][0][i] = b[i];
  for (int i = 1; i < 20; ++i) {
    for (int j = (1 << (i - 1)); j <= n; ++j) f[0][i][j] = std::max(f[0][i - 1][j], f[0][i - 1][j - (1 << (i - 1))]);
    for (int j = (1 << (i - 1)); j <= m; ++j) f[3][i][j] = std::max(f[3][i - 1][j], f[3][i - 1][j - (1 << (i - 1))]);
    for (int j = m - (1 << (i - 1)); j > 0; --j) f[1][i][j] = std::max(f[1][i - 1][j], f[1][i - 1][j + (1 << (i - 1))]);
    for (int j = n - (1 << (i - 1)); j > 0; --j) f[2][i][j] = std::max(f[2][i - 1][j], f[2][i - 1][j + (1 << (i - 1))]);
  }
  return q;
}

std::map<std::tuple<int, int, int>, int> mem;

int dfs(int x, int y, int k) {
  x += dx[k], y += dy[k];
  if (!(0 < x && x <= n && 0 < y && y <= m)) return 0;
  int &res = mem[std::make_tuple(x, y, k)];
  if (res) return res;
  if (k & 1) {
    int cur = a[x];
    for (int i = 19; i >= 0; --i) if (f[k][i][y] && f[k][i][y] <= cur) y += dy[k] << i, res += 1 << i;
    if (0 < y && y <= m) res += std::max(dfs(x, y, 0), dfs(x, y, 2)) + 1;
  } else {
    int cur = b[y];
    for (int i = 19; i >= 0; --i) if (f[k][i][x] && f[k][i][x] <= cur) x += dx[k] << i, res += 1 << i;
    if (0 < x && x <= n) res += std::max(dfs(x, y, 1), dfs(x, y, 3)) + 1;
  }
  return res;
}

int main() {
  for (int q = init(); q--;) {
    int x, y;
    scanf("%d%d", &x, &y);
    int ans = dfs(x, y, 0);
    for (int i = 1; i < 4; ++i) ans = std::max(ans, dfs(x, y, i));
    printf("%d\n", ans);
  }
  return 0;
}

Compilation message

abduction2.cpp: In function 'int init()':
abduction2.cpp:14:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &n, &m, &q);
                              ^
abduction2.cpp:15:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
                                                  ^
abduction2.cpp:16:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
                                                  ^
abduction2.cpp: In function 'int main()':
abduction2.cpp:51:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &x, &y);
                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17196 KB Output is correct
2 Correct 3 ms 17196 KB Output is correct
3 Correct 0 ms 17196 KB Output is correct
4 Correct 3 ms 17196 KB Output is correct
5 Correct 3 ms 17196 KB Output is correct
6 Correct 3 ms 17196 KB Output is correct
7 Correct 0 ms 17196 KB Output is correct
8 Correct 0 ms 17196 KB Output is correct
9 Correct 0 ms 17196 KB Output is correct
10 Correct 3 ms 17196 KB Output is correct
11 Correct 3 ms 17196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17196 KB Output is correct
2 Correct 3 ms 17196 KB Output is correct
3 Correct 0 ms 17196 KB Output is correct
4 Correct 3 ms 17196 KB Output is correct
5 Correct 3 ms 17196 KB Output is correct
6 Correct 3 ms 17196 KB Output is correct
7 Correct 0 ms 17196 KB Output is correct
8 Correct 0 ms 17196 KB Output is correct
9 Correct 0 ms 17196 KB Output is correct
10 Correct 3 ms 17196 KB Output is correct
11 Correct 3 ms 17196 KB Output is correct
12 Correct 0 ms 17196 KB Output is correct
13 Correct 0 ms 17196 KB Output is correct
14 Correct 3 ms 17196 KB Output is correct
15 Correct 6 ms 17196 KB Output is correct
16 Correct 3 ms 17196 KB Output is correct
17 Correct 0 ms 17196 KB Output is correct
18 Correct 3 ms 17196 KB Output is correct
19 Correct 6 ms 17592 KB Output is correct
20 Correct 3 ms 17724 KB Output is correct
21 Correct 3 ms 17592 KB Output is correct
22 Correct 6 ms 17988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17196 KB Output is correct
2 Correct 3 ms 17196 KB Output is correct
3 Correct 0 ms 17196 KB Output is correct
4 Correct 3 ms 17196 KB Output is correct
5 Correct 3 ms 17196 KB Output is correct
6 Correct 3 ms 17196 KB Output is correct
7 Correct 0 ms 17196 KB Output is correct
8 Correct 0 ms 17196 KB Output is correct
9 Correct 0 ms 17196 KB Output is correct
10 Correct 3 ms 17196 KB Output is correct
11 Correct 3 ms 17196 KB Output is correct
12 Correct 0 ms 17196 KB Output is correct
13 Correct 0 ms 17196 KB Output is correct
14 Correct 3 ms 17196 KB Output is correct
15 Correct 6 ms 17196 KB Output is correct
16 Correct 3 ms 17196 KB Output is correct
17 Correct 0 ms 17196 KB Output is correct
18 Correct 3 ms 17196 KB Output is correct
19 Correct 6 ms 17592 KB Output is correct
20 Correct 3 ms 17724 KB Output is correct
21 Correct 3 ms 17592 KB Output is correct
22 Correct 6 ms 17988 KB Output is correct
23 Correct 26 ms 17196 KB Output is correct
24 Correct 29 ms 17196 KB Output is correct
25 Correct 43 ms 17196 KB Output is correct
26 Correct 23 ms 17196 KB Output is correct
27 Correct 36 ms 17196 KB Output is correct
28 Correct 69 ms 23720 KB Output is correct
29 Correct 19 ms 18092 KB Output is correct
30 Correct 119 ms 27812 KB Output is correct
31 Correct 153 ms 30952 KB Output is correct
32 Correct 33 ms 17724 KB Output is correct
33 Correct 56 ms 20424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 17592 KB Output is correct
2 Correct 6 ms 17592 KB Output is correct
3 Correct 3 ms 17592 KB Output is correct
4 Correct 9 ms 17592 KB Output is correct
5 Correct 3 ms 17592 KB Output is correct
6 Correct 3 ms 17460 KB Output is correct
7 Correct 3 ms 17460 KB Output is correct
8 Correct 6 ms 17988 KB Output is correct
9 Correct 6 ms 17988 KB Output is correct
10 Correct 3 ms 17988 KB Output is correct
11 Correct 6 ms 18252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 17196 KB Output is correct
2 Correct 3 ms 17196 KB Output is correct
3 Correct 0 ms 17196 KB Output is correct
4 Correct 3 ms 17196 KB Output is correct
5 Correct 3 ms 17196 KB Output is correct
6 Correct 3 ms 17196 KB Output is correct
7 Correct 0 ms 17196 KB Output is correct
8 Correct 0 ms 17196 KB Output is correct
9 Correct 0 ms 17196 KB Output is correct
10 Correct 3 ms 17196 KB Output is correct
11 Correct 3 ms 17196 KB Output is correct
12 Correct 0 ms 17196 KB Output is correct
13 Correct 0 ms 17196 KB Output is correct
14 Correct 3 ms 17196 KB Output is correct
15 Correct 6 ms 17196 KB Output is correct
16 Correct 3 ms 17196 KB Output is correct
17 Correct 0 ms 17196 KB Output is correct
18 Correct 3 ms 17196 KB Output is correct
19 Correct 6 ms 17592 KB Output is correct
20 Correct 3 ms 17724 KB Output is correct
21 Correct 3 ms 17592 KB Output is correct
22 Correct 6 ms 17988 KB Output is correct
23 Correct 26 ms 17196 KB Output is correct
24 Correct 29 ms 17196 KB Output is correct
25 Correct 43 ms 17196 KB Output is correct
26 Correct 23 ms 17196 KB Output is correct
27 Correct 36 ms 17196 KB Output is correct
28 Correct 69 ms 23720 KB Output is correct
29 Correct 19 ms 18092 KB Output is correct
30 Correct 119 ms 27812 KB Output is correct
31 Correct 153 ms 30952 KB Output is correct
32 Correct 33 ms 17724 KB Output is correct
33 Correct 56 ms 20424 KB Output is correct
34 Correct 6 ms 17592 KB Output is correct
35 Correct 6 ms 17592 KB Output is correct
36 Correct 3 ms 17592 KB Output is correct
37 Correct 9 ms 17592 KB Output is correct
38 Correct 3 ms 17592 KB Output is correct
39 Correct 3 ms 17460 KB Output is correct
40 Correct 3 ms 17460 KB Output is correct
41 Correct 6 ms 17988 KB Output is correct
42 Correct 6 ms 17988 KB Output is correct
43 Correct 3 ms 17988 KB Output is correct
44 Correct 6 ms 18252 KB Output is correct
45 Correct 29 ms 17724 KB Output is correct
46 Correct 26 ms 17724 KB Output is correct
47 Correct 39 ms 17856 KB Output is correct
48 Correct 33 ms 17724 KB Output is correct
49 Correct 39 ms 17724 KB Output is correct
50 Correct 73 ms 24232 KB Output is correct
51 Correct 66 ms 24828 KB Output is correct
52 Correct 186 ms 36376 KB Output is correct
53 Correct 183 ms 35652 KB Output is correct
54 Correct 176 ms 34604 KB Output is correct
55 Incorrect 273 ms 43752 KB Output isn't correct
56 Halted 0 ms 0 KB -