# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
61068 |
2018-07-25T07:34:14 Z |
강태규(#1759) |
Abduction 2 (JOI17_abduction2) |
C++11 |
|
4985 ms |
253052 KB |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
int h, w, q;
int a[50001];
int b[50001];
struct go {
int x, y, t;
go(int x, int y, int t) : x(x), y(y), t(t) {}
bool operator<(const go &p) const {
if (x != p.x) return x < p.x;
if (y != p.y) return y < p.y;
return t < p.t;
}
};
map<go, llong> dp;
struct segtree {
int seg[1 << 17];
int sz;
void init(int a[], int i, int s, int e) {
if (s == e) {
seg[i] = a[s];
return;
}
int m = (s + e) / 2;
init(a, i << 1, s, m);
init(a, i << 1 | 1, m + 1, e);
seg[i] = max(seg[i << 1], seg[i << 1 | 1]);
}
void init(int x[], int n) {
init(x, 1, 1, sz = n);
}
int findLR(int i, int s, int e, int x, int v) {
if (seg[i] < v) return 0;
if (x < s) return 0;
if (s == e) return s;
int m = (s + e) / 2;
int r = findLR(i << 1 | 1, m + 1, e, x, v);
if (r) return r;
return findLR(i << 1, s, m, x, v);
}
int findLR(int r, int x) {
return findLR(1, 1, sz, r, x);
}
int findRL(int i, int s, int e, int x, int v) {
if (seg[i] < v) return 0;
if (e < x) return 0;
if (s == e) return s;
int m = (s + e) / 2;
int r = findRL(i << 1, s, m, x, v);
if (r) return r;
return findRL(i << 1 | 1, m + 1, e, x, v);
}
int findRL(int l, int x) {
int r = findRL(1, 1, sz, l, x);
if (r) return r;
return sz + 1;
}
} segh, segw;
llong pro_dp(int x, int y, int t) {
map<go, llong>::iterator it = dp.find(go(x, y, t));
if (it != dp.end()) return it->second;
llong ret = 0;
if (t == 0) {
int r = segw.findRL(y + 1, a[x]);
if (r <= w) ret = r - y + max(pro_dp(x, r, 1), pro_dp(x, r, 3));
else ret = w - y;
}
if (t == 1) {
int d = segh.findRL(x + 1, b[y]);
if (d <= h) ret = d - x + max(pro_dp(d, y, 0), pro_dp(d, y, 2));
else ret = h - x;
}
if (t == 2) {
int l = segw.findLR(y - 1, a[x]);
if (l) ret = y - l + max(pro_dp(x, l, 1), pro_dp(x, l, 3));
else ret = y - 1;
}
if (t == 3) {
int u = segh.findLR(x - 1, b[y]);
if (u) ret = x - u + max(pro_dp(u, y, 0), pro_dp(u, y, 2));
else ret = x - 1;
}
return dp[go(x, y, t)] = ret;
}
int main() {
scanf("%d%d%d", &h, &w, &q);
for (int i = 1; i <= h; ++i) {
scanf("%d", a + i);
}
segh.init(a, h);
for (int i = 1; i <= w; ++i) {
scanf("%d", b + i);
}
segw.init(b, w);
for (int i = 0; i < q; ++i) {
int x, y;
scanf("%d%d", &x, &y);
llong ret = 0;
for (int j = 0; j < 4; ++j) {
ret = max(ret, pro_dp(x, y, j));
}
printf("%lld\n", ret);
}
return 0;
}
Compilation message
abduction2.cpp: In function 'int main()':
abduction2.cpp:119:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &h, &w, &q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
abduction2.cpp:121:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", a + i);
~~~~~^~~~~~~~~~~~~
abduction2.cpp:125:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", b + i);
~~~~~^~~~~~~~~~~~~
abduction2.cpp:131:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &x, &y);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
3 ms |
588 KB |
Output is correct |
10 |
Correct |
3 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
3 ms |
588 KB |
Output is correct |
10 |
Correct |
3 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
4 ms |
596 KB |
Output is correct |
18 |
Correct |
5 ms |
724 KB |
Output is correct |
19 |
Correct |
8 ms |
980 KB |
Output is correct |
20 |
Correct |
9 ms |
1196 KB |
Output is correct |
21 |
Correct |
9 ms |
1196 KB |
Output is correct |
22 |
Correct |
13 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
3 ms |
588 KB |
Output is correct |
10 |
Correct |
3 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
4 ms |
596 KB |
Output is correct |
18 |
Correct |
5 ms |
724 KB |
Output is correct |
19 |
Correct |
8 ms |
980 KB |
Output is correct |
20 |
Correct |
9 ms |
1196 KB |
Output is correct |
21 |
Correct |
9 ms |
1196 KB |
Output is correct |
22 |
Correct |
13 ms |
1620 KB |
Output is correct |
23 |
Correct |
26 ms |
2004 KB |
Output is correct |
24 |
Correct |
29 ms |
2004 KB |
Output is correct |
25 |
Correct |
29 ms |
2004 KB |
Output is correct |
26 |
Correct |
27 ms |
2008 KB |
Output is correct |
27 |
Correct |
28 ms |
2008 KB |
Output is correct |
28 |
Correct |
80 ms |
13264 KB |
Output is correct |
29 |
Correct |
32 ms |
13264 KB |
Output is correct |
30 |
Correct |
146 ms |
15124 KB |
Output is correct |
31 |
Correct |
203 ms |
18752 KB |
Output is correct |
32 |
Correct |
30 ms |
18752 KB |
Output is correct |
33 |
Correct |
76 ms |
18752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
18752 KB |
Output is correct |
2 |
Correct |
10 ms |
18752 KB |
Output is correct |
3 |
Correct |
9 ms |
18752 KB |
Output is correct |
4 |
Correct |
9 ms |
18752 KB |
Output is correct |
5 |
Correct |
7 ms |
18752 KB |
Output is correct |
6 |
Correct |
6 ms |
18752 KB |
Output is correct |
7 |
Correct |
7 ms |
18752 KB |
Output is correct |
8 |
Correct |
15 ms |
18752 KB |
Output is correct |
9 |
Correct |
13 ms |
18752 KB |
Output is correct |
10 |
Correct |
14 ms |
18752 KB |
Output is correct |
11 |
Correct |
17 ms |
18752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
588 KB |
Output is correct |
9 |
Correct |
3 ms |
588 KB |
Output is correct |
10 |
Correct |
3 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
4 ms |
596 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
4 ms |
596 KB |
Output is correct |
18 |
Correct |
5 ms |
724 KB |
Output is correct |
19 |
Correct |
8 ms |
980 KB |
Output is correct |
20 |
Correct |
9 ms |
1196 KB |
Output is correct |
21 |
Correct |
9 ms |
1196 KB |
Output is correct |
22 |
Correct |
13 ms |
1620 KB |
Output is correct |
23 |
Correct |
26 ms |
2004 KB |
Output is correct |
24 |
Correct |
29 ms |
2004 KB |
Output is correct |
25 |
Correct |
29 ms |
2004 KB |
Output is correct |
26 |
Correct |
27 ms |
2008 KB |
Output is correct |
27 |
Correct |
28 ms |
2008 KB |
Output is correct |
28 |
Correct |
80 ms |
13264 KB |
Output is correct |
29 |
Correct |
32 ms |
13264 KB |
Output is correct |
30 |
Correct |
146 ms |
15124 KB |
Output is correct |
31 |
Correct |
203 ms |
18752 KB |
Output is correct |
32 |
Correct |
30 ms |
18752 KB |
Output is correct |
33 |
Correct |
76 ms |
18752 KB |
Output is correct |
34 |
Correct |
7 ms |
18752 KB |
Output is correct |
35 |
Correct |
10 ms |
18752 KB |
Output is correct |
36 |
Correct |
9 ms |
18752 KB |
Output is correct |
37 |
Correct |
9 ms |
18752 KB |
Output is correct |
38 |
Correct |
7 ms |
18752 KB |
Output is correct |
39 |
Correct |
6 ms |
18752 KB |
Output is correct |
40 |
Correct |
7 ms |
18752 KB |
Output is correct |
41 |
Correct |
15 ms |
18752 KB |
Output is correct |
42 |
Correct |
13 ms |
18752 KB |
Output is correct |
43 |
Correct |
14 ms |
18752 KB |
Output is correct |
44 |
Correct |
17 ms |
18752 KB |
Output is correct |
45 |
Correct |
34 ms |
18752 KB |
Output is correct |
46 |
Correct |
36 ms |
18752 KB |
Output is correct |
47 |
Correct |
33 ms |
18752 KB |
Output is correct |
48 |
Correct |
33 ms |
18752 KB |
Output is correct |
49 |
Correct |
31 ms |
18752 KB |
Output is correct |
50 |
Correct |
88 ms |
18752 KB |
Output is correct |
51 |
Correct |
98 ms |
18752 KB |
Output is correct |
52 |
Correct |
273 ms |
23020 KB |
Output is correct |
53 |
Correct |
297 ms |
23020 KB |
Output is correct |
54 |
Correct |
281 ms |
23020 KB |
Output is correct |
55 |
Correct |
478 ms |
31816 KB |
Output is correct |
56 |
Correct |
4985 ms |
253052 KB |
Output is correct |
57 |
Correct |
1080 ms |
253052 KB |
Output is correct |
58 |
Correct |
973 ms |
253052 KB |
Output is correct |
59 |
Correct |
962 ms |
253052 KB |
Output is correct |