# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
61036 | 2018-07-25T06:21:43 Z | 김세빈(#1761) | Abduction 2 (JOI17_abduction2) | C++11 | 2413 ms | 150140 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; map <ll, ll> M; ll A[50505], B[50505]; ll AL[17][50505], AR[17][50505], BL[17][50505], BR[17][50505]; ll n, m; ll f(ll x, ll y, ll d) { ll v = (ll) (x - 1) * m * 2 + (y - 1) * 2 + d; if(M[v]) return M[v]; ll l, r, ret, i; if(d == 0){ l = y - 1, r = y + 1; for(i=16; i>=0; i--){ if(l - (1<<i) + 1 >= 1 && BL[i][l] <= A[x]) l -= 1<<i; if(r + (1<<i) - 1 <= m && BR[i][r] <= A[x]) r += 1<<i; } l = l < 1? (y - 1) : (y - l) + f(x, l, 1); r = r > m? (m - y) : (r - y) + f(x, r, 1); ret = max(l, r); } else{ l = x - 1, r = x + 1; for(i=16; i>=0; i--){ if(l - (1<<i) + 1 >= 1 && AL[i][l] <= B[y]) l -= 1<<i; if(r + (1<<i) - 1 <= n && AR[i][r] <= B[y]) r += 1<<i; } l = l < 1? (x - 1) : (x - l) + f(l, y, 0); r = r > n? (n - x) : (r - x) + f(r, y, 0); ret = max(l, r); } return M[v] = ret; } int main() { ll q, i, j, a, b; scanf("%lld%lld%lld", &n, &m, &q); for(i=1; i<=n; i++){ scanf("%lld", A+i); AL[0][i] = AR[0][i] = A[i]; } for(i=1; i<=16; i++){ for(j=1; j<=n; j++){ if(j - (1<<i) + 1 >= 1) AL[i][j] = max(AL[i-1][j], AL[i-1][j - (1<<i-1)]); if(j + (1<<i) - 1 <= n) AR[i][j] = max(AR[i-1][j], AR[i-1][j + (1<<i-1)]); } } for(i=1; i<=m; i++){ scanf("%lld", B+i); BL[0][i] = BR[0][i] = B[i]; } for(i=1; i<=16; i++){ for(j=1; j<=m; j++){ if(j - (1<<i) + 1 >= 1) BL[i][j] = max(BL[i-1][j], BL[i-1][j - (1<<i-1)]); if(j + (1<<i) - 1 <= m) BR[i][j] = max(BR[i-1][j], BR[i-1][j + (1<<i-1)]); } } for(; q--; ){ scanf("%lld%lld", &a, &b); printf("%lld\n", max(f(a, b, 0), f(a, b, 1))); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 520 KB | Output is correct |
4 | Correct | 2 ms | 520 KB | Output is correct |
5 | Correct | 3 ms | 632 KB | Output is correct |
6 | Correct | 2 ms | 632 KB | Output is correct |
7 | Correct | 2 ms | 632 KB | Output is correct |
8 | Correct | 2 ms | 632 KB | Output is correct |
9 | Correct | 3 ms | 632 KB | Output is correct |
10 | Correct | 3 ms | 632 KB | Output is correct |
11 | Correct | 2 ms | 632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 520 KB | Output is correct |
4 | Correct | 2 ms | 520 KB | Output is correct |
5 | Correct | 3 ms | 632 KB | Output is correct |
6 | Correct | 2 ms | 632 KB | Output is correct |
7 | Correct | 2 ms | 632 KB | Output is correct |
8 | Correct | 2 ms | 632 KB | Output is correct |
9 | Correct | 3 ms | 632 KB | Output is correct |
10 | Correct | 3 ms | 632 KB | Output is correct |
11 | Correct | 2 ms | 632 KB | Output is correct |
12 | Correct | 4 ms | 1268 KB | Output is correct |
13 | Correct | 4 ms | 1268 KB | Output is correct |
14 | Correct | 4 ms | 1396 KB | Output is correct |
15 | Correct | 4 ms | 1444 KB | Output is correct |
16 | Correct | 5 ms | 1472 KB | Output is correct |
17 | Correct | 5 ms | 1472 KB | Output is correct |
18 | Correct | 5 ms | 1516 KB | Output is correct |
19 | Correct | 6 ms | 1644 KB | Output is correct |
20 | Correct | 8 ms | 1772 KB | Output is correct |
21 | Correct | 7 ms | 1772 KB | Output is correct |
22 | Correct | 10 ms | 1900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 520 KB | Output is correct |
4 | Correct | 2 ms | 520 KB | Output is correct |
5 | Correct | 3 ms | 632 KB | Output is correct |
6 | Correct | 2 ms | 632 KB | Output is correct |
7 | Correct | 2 ms | 632 KB | Output is correct |
8 | Correct | 2 ms | 632 KB | Output is correct |
9 | Correct | 3 ms | 632 KB | Output is correct |
10 | Correct | 3 ms | 632 KB | Output is correct |
11 | Correct | 2 ms | 632 KB | Output is correct |
12 | Correct | 4 ms | 1268 KB | Output is correct |
13 | Correct | 4 ms | 1268 KB | Output is correct |
14 | Correct | 4 ms | 1396 KB | Output is correct |
15 | Correct | 4 ms | 1444 KB | Output is correct |
16 | Correct | 5 ms | 1472 KB | Output is correct |
17 | Correct | 5 ms | 1472 KB | Output is correct |
18 | Correct | 5 ms | 1516 KB | Output is correct |
19 | Correct | 6 ms | 1644 KB | Output is correct |
20 | Correct | 8 ms | 1772 KB | Output is correct |
21 | Correct | 7 ms | 1772 KB | Output is correct |
22 | Correct | 10 ms | 1900 KB | Output is correct |
23 | Correct | 42 ms | 24592 KB | Output is correct |
24 | Correct | 50 ms | 24620 KB | Output is correct |
25 | Correct | 43 ms | 24684 KB | Output is correct |
26 | Correct | 42 ms | 24684 KB | Output is correct |
27 | Correct | 52 ms | 24684 KB | Output is correct |
28 | Correct | 78 ms | 30304 KB | Output is correct |
29 | Correct | 43 ms | 30304 KB | Output is correct |
30 | Correct | 119 ms | 31228 KB | Output is correct |
31 | Correct | 147 ms | 33020 KB | Output is correct |
32 | Correct | 44 ms | 33020 KB | Output is correct |
33 | Correct | 57 ms | 33020 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 33020 KB | Output is correct |
2 | Correct | 5 ms | 33020 KB | Output is correct |
3 | Correct | 7 ms | 33020 KB | Output is correct |
4 | Correct | 6 ms | 33020 KB | Output is correct |
5 | Correct | 8 ms | 33020 KB | Output is correct |
6 | Correct | 6 ms | 33020 KB | Output is correct |
7 | Correct | 7 ms | 33020 KB | Output is correct |
8 | Correct | 8 ms | 33020 KB | Output is correct |
9 | Correct | 8 ms | 33020 KB | Output is correct |
10 | Correct | 9 ms | 33020 KB | Output is correct |
11 | Correct | 10 ms | 33020 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 520 KB | Output is correct |
4 | Correct | 2 ms | 520 KB | Output is correct |
5 | Correct | 3 ms | 632 KB | Output is correct |
6 | Correct | 2 ms | 632 KB | Output is correct |
7 | Correct | 2 ms | 632 KB | Output is correct |
8 | Correct | 2 ms | 632 KB | Output is correct |
9 | Correct | 3 ms | 632 KB | Output is correct |
10 | Correct | 3 ms | 632 KB | Output is correct |
11 | Correct | 2 ms | 632 KB | Output is correct |
12 | Correct | 4 ms | 1268 KB | Output is correct |
13 | Correct | 4 ms | 1268 KB | Output is correct |
14 | Correct | 4 ms | 1396 KB | Output is correct |
15 | Correct | 4 ms | 1444 KB | Output is correct |
16 | Correct | 5 ms | 1472 KB | Output is correct |
17 | Correct | 5 ms | 1472 KB | Output is correct |
18 | Correct | 5 ms | 1516 KB | Output is correct |
19 | Correct | 6 ms | 1644 KB | Output is correct |
20 | Correct | 8 ms | 1772 KB | Output is correct |
21 | Correct | 7 ms | 1772 KB | Output is correct |
22 | Correct | 10 ms | 1900 KB | Output is correct |
23 | Correct | 42 ms | 24592 KB | Output is correct |
24 | Correct | 50 ms | 24620 KB | Output is correct |
25 | Correct | 43 ms | 24684 KB | Output is correct |
26 | Correct | 42 ms | 24684 KB | Output is correct |
27 | Correct | 52 ms | 24684 KB | Output is correct |
28 | Correct | 78 ms | 30304 KB | Output is correct |
29 | Correct | 43 ms | 30304 KB | Output is correct |
30 | Correct | 119 ms | 31228 KB | Output is correct |
31 | Correct | 147 ms | 33020 KB | Output is correct |
32 | Correct | 44 ms | 33020 KB | Output is correct |
33 | Correct | 57 ms | 33020 KB | Output is correct |
34 | Correct | 6 ms | 33020 KB | Output is correct |
35 | Correct | 5 ms | 33020 KB | Output is correct |
36 | Correct | 7 ms | 33020 KB | Output is correct |
37 | Correct | 6 ms | 33020 KB | Output is correct |
38 | Correct | 8 ms | 33020 KB | Output is correct |
39 | Correct | 6 ms | 33020 KB | Output is correct |
40 | Correct | 7 ms | 33020 KB | Output is correct |
41 | Correct | 8 ms | 33020 KB | Output is correct |
42 | Correct | 8 ms | 33020 KB | Output is correct |
43 | Correct | 9 ms | 33020 KB | Output is correct |
44 | Correct | 10 ms | 33020 KB | Output is correct |
45 | Correct | 45 ms | 33020 KB | Output is correct |
46 | Correct | 54 ms | 33020 KB | Output is correct |
47 | Correct | 60 ms | 33020 KB | Output is correct |
48 | Correct | 58 ms | 33020 KB | Output is correct |
49 | Correct | 60 ms | 33020 KB | Output is correct |
50 | Correct | 121 ms | 33020 KB | Output is correct |
51 | Correct | 89 ms | 33020 KB | Output is correct |
52 | Correct | 189 ms | 35160 KB | Output is correct |
53 | Correct | 189 ms | 35160 KB | Output is correct |
54 | Correct | 195 ms | 35160 KB | Output is correct |
55 | Correct | 304 ms | 39548 KB | Output is correct |
56 | Correct | 2413 ms | 150140 KB | Output is correct |
57 | Correct | 584 ms | 150140 KB | Output is correct |
58 | Correct | 567 ms | 150140 KB | Output is correct |
59 | Correct | 479 ms | 150140 KB | Output is correct |