# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
61032 |
2018-07-25T06:19:03 Z |
김세빈(#1761) |
유괴 2 (JOI17_abduction2) |
C++11 |
|
2466 ms |
125936 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
unordered_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);
}
// printf("%lld %lld %lld %lld\n", x, y, d, ret);
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
abduction2.cpp: In function 'int main()':
abduction2.cpp:58:72: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
if(j - (1<<i) + 1 >= 1) AL[i][j] = max(AL[i-1][j], AL[i-1][j - (1<<i-1)]);
~^~
abduction2.cpp:59:72: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
if(j + (1<<i) - 1 <= n) AR[i][j] = max(AR[i-1][j], AR[i-1][j + (1<<i-1)]);
~^~
abduction2.cpp:70:72: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
if(j - (1<<i) + 1 >= 1) BL[i][j] = max(BL[i-1][j], BL[i-1][j - (1<<i-1)]);
~^~
abduction2.cpp:71:72: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
if(j + (1<<i) - 1 <= m) BR[i][j] = max(BR[i-1][j], BR[i-1][j + (1<<i-1)]);
~^~
abduction2.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld", &n, &m, &q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
abduction2.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", A+i);
~~~~~^~~~~~~~~~~~~
abduction2.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", B+i);
~~~~~^~~~~~~~~~~~~
abduction2.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &a, &b);
~~~~~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
3 ms |
616 KB |
Output is correct |
5 |
Correct |
2 ms |
616 KB |
Output is correct |
6 |
Correct |
3 ms |
616 KB |
Output is correct |
7 |
Correct |
3 ms |
616 KB |
Output is correct |
8 |
Correct |
3 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
3 ms |
616 KB |
Output is correct |
11 |
Correct |
3 ms |
616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
3 ms |
616 KB |
Output is correct |
5 |
Correct |
2 ms |
616 KB |
Output is correct |
6 |
Correct |
3 ms |
616 KB |
Output is correct |
7 |
Correct |
3 ms |
616 KB |
Output is correct |
8 |
Correct |
3 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
3 ms |
616 KB |
Output is correct |
11 |
Correct |
3 ms |
616 KB |
Output is correct |
12 |
Correct |
4 ms |
1312 KB |
Output is correct |
13 |
Correct |
4 ms |
1456 KB |
Output is correct |
14 |
Correct |
4 ms |
1456 KB |
Output is correct |
15 |
Correct |
5 ms |
1456 KB |
Output is correct |
16 |
Correct |
3 ms |
1456 KB |
Output is correct |
17 |
Correct |
4 ms |
1456 KB |
Output is correct |
18 |
Correct |
5 ms |
1512 KB |
Output is correct |
19 |
Correct |
7 ms |
1520 KB |
Output is correct |
20 |
Correct |
7 ms |
1644 KB |
Output is correct |
21 |
Correct |
6 ms |
1644 KB |
Output is correct |
22 |
Correct |
6 ms |
1772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
3 ms |
616 KB |
Output is correct |
5 |
Correct |
2 ms |
616 KB |
Output is correct |
6 |
Correct |
3 ms |
616 KB |
Output is correct |
7 |
Correct |
3 ms |
616 KB |
Output is correct |
8 |
Correct |
3 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
3 ms |
616 KB |
Output is correct |
11 |
Correct |
3 ms |
616 KB |
Output is correct |
12 |
Correct |
4 ms |
1312 KB |
Output is correct |
13 |
Correct |
4 ms |
1456 KB |
Output is correct |
14 |
Correct |
4 ms |
1456 KB |
Output is correct |
15 |
Correct |
5 ms |
1456 KB |
Output is correct |
16 |
Correct |
3 ms |
1456 KB |
Output is correct |
17 |
Correct |
4 ms |
1456 KB |
Output is correct |
18 |
Correct |
5 ms |
1512 KB |
Output is correct |
19 |
Correct |
7 ms |
1520 KB |
Output is correct |
20 |
Correct |
7 ms |
1644 KB |
Output is correct |
21 |
Correct |
6 ms |
1644 KB |
Output is correct |
22 |
Correct |
6 ms |
1772 KB |
Output is correct |
23 |
Correct |
49 ms |
24644 KB |
Output is correct |
24 |
Correct |
50 ms |
24644 KB |
Output is correct |
25 |
Correct |
62 ms |
24644 KB |
Output is correct |
26 |
Correct |
51 ms |
24644 KB |
Output is correct |
27 |
Correct |
61 ms |
24644 KB |
Output is correct |
28 |
Correct |
87 ms |
28204 KB |
Output is correct |
29 |
Correct |
43 ms |
28204 KB |
Output is correct |
30 |
Correct |
97 ms |
28812 KB |
Output is correct |
31 |
Correct |
119 ms |
29836 KB |
Output is correct |
32 |
Correct |
42 ms |
29836 KB |
Output is correct |
33 |
Correct |
54 ms |
29836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
29836 KB |
Output is correct |
2 |
Correct |
5 ms |
29836 KB |
Output is correct |
3 |
Correct |
8 ms |
29836 KB |
Output is correct |
4 |
Correct |
5 ms |
29836 KB |
Output is correct |
5 |
Correct |
4 ms |
29836 KB |
Output is correct |
6 |
Correct |
4 ms |
29836 KB |
Output is correct |
7 |
Correct |
6 ms |
29836 KB |
Output is correct |
8 |
Correct |
7 ms |
29836 KB |
Output is correct |
9 |
Correct |
6 ms |
29836 KB |
Output is correct |
10 |
Correct |
6 ms |
29836 KB |
Output is correct |
11 |
Correct |
8 ms |
29836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
3 ms |
616 KB |
Output is correct |
5 |
Correct |
2 ms |
616 KB |
Output is correct |
6 |
Correct |
3 ms |
616 KB |
Output is correct |
7 |
Correct |
3 ms |
616 KB |
Output is correct |
8 |
Correct |
3 ms |
616 KB |
Output is correct |
9 |
Correct |
2 ms |
616 KB |
Output is correct |
10 |
Correct |
3 ms |
616 KB |
Output is correct |
11 |
Correct |
3 ms |
616 KB |
Output is correct |
12 |
Correct |
4 ms |
1312 KB |
Output is correct |
13 |
Correct |
4 ms |
1456 KB |
Output is correct |
14 |
Correct |
4 ms |
1456 KB |
Output is correct |
15 |
Correct |
5 ms |
1456 KB |
Output is correct |
16 |
Correct |
3 ms |
1456 KB |
Output is correct |
17 |
Correct |
4 ms |
1456 KB |
Output is correct |
18 |
Correct |
5 ms |
1512 KB |
Output is correct |
19 |
Correct |
7 ms |
1520 KB |
Output is correct |
20 |
Correct |
7 ms |
1644 KB |
Output is correct |
21 |
Correct |
6 ms |
1644 KB |
Output is correct |
22 |
Correct |
6 ms |
1772 KB |
Output is correct |
23 |
Correct |
49 ms |
24644 KB |
Output is correct |
24 |
Correct |
50 ms |
24644 KB |
Output is correct |
25 |
Correct |
62 ms |
24644 KB |
Output is correct |
26 |
Correct |
51 ms |
24644 KB |
Output is correct |
27 |
Correct |
61 ms |
24644 KB |
Output is correct |
28 |
Correct |
87 ms |
28204 KB |
Output is correct |
29 |
Correct |
43 ms |
28204 KB |
Output is correct |
30 |
Correct |
97 ms |
28812 KB |
Output is correct |
31 |
Correct |
119 ms |
29836 KB |
Output is correct |
32 |
Correct |
42 ms |
29836 KB |
Output is correct |
33 |
Correct |
54 ms |
29836 KB |
Output is correct |
34 |
Correct |
6 ms |
29836 KB |
Output is correct |
35 |
Correct |
5 ms |
29836 KB |
Output is correct |
36 |
Correct |
8 ms |
29836 KB |
Output is correct |
37 |
Correct |
5 ms |
29836 KB |
Output is correct |
38 |
Correct |
4 ms |
29836 KB |
Output is correct |
39 |
Correct |
4 ms |
29836 KB |
Output is correct |
40 |
Correct |
6 ms |
29836 KB |
Output is correct |
41 |
Correct |
7 ms |
29836 KB |
Output is correct |
42 |
Correct |
6 ms |
29836 KB |
Output is correct |
43 |
Correct |
6 ms |
29836 KB |
Output is correct |
44 |
Correct |
8 ms |
29836 KB |
Output is correct |
45 |
Correct |
44 ms |
29836 KB |
Output is correct |
46 |
Correct |
49 ms |
29836 KB |
Output is correct |
47 |
Correct |
51 ms |
29836 KB |
Output is correct |
48 |
Correct |
58 ms |
29836 KB |
Output is correct |
49 |
Correct |
61 ms |
29836 KB |
Output is correct |
50 |
Correct |
104 ms |
29836 KB |
Output is correct |
51 |
Correct |
128 ms |
29836 KB |
Output is correct |
52 |
Correct |
196 ms |
31804 KB |
Output is correct |
53 |
Correct |
197 ms |
31804 KB |
Output is correct |
54 |
Correct |
181 ms |
31804 KB |
Output is correct |
55 |
Correct |
194 ms |
33980 KB |
Output is correct |
56 |
Correct |
2466 ms |
125936 KB |
Output is correct |
57 |
Correct |
571 ms |
125936 KB |
Output is correct |
58 |
Correct |
514 ms |
125936 KB |
Output is correct |
59 |
Correct |
587 ms |
125936 KB |
Output is correct |