Submission #308363

# Submission time Handle Problem Language Result Execution time Memory
308363 2020-10-01T01:18:16 Z thecodingwizard Abduction 2 (JOI17_abduction2) C++11
44 / 100
5000 ms 16660 KB
#include <bits/stdc++.h>

using namespace std;

#define ii pair<int, int>
#define f first
#define s second
#define mp make_pair

int h, w, q; 
int A[50000], B[50000];

map<pair<int, ii>, int> memo;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
int dp(int i, int j, int d) {
    auto memoIdx = mp(i, mp(j, d));
    if (memo.count(memoIdx)) {
        return memo[memoIdx];
    }

    int ans = 0;
    int k = 1;
    while (true) {
        int a = i + dx[d]*k, b = j + dy[d]*k;
        if (a < 0 || a >= h || b < 0 || b >= w) break;
        ans++;
        if ((d == 0 || d == 2) && A[a] > B[j]) {
            ans += max(dp(a, b, 1), dp(a, b, 3));
            break;
        }
        if ((d == 1 || d == 3) && B[b] > A[i]) {
            ans += max(dp(a, b, 0), dp(a, b, 2));
            break;
        }
        k++;
    }

    return memo[memoIdx] = ans;
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> h >> w >> q;
    for (int i = 0; i < h; i++) cin >> A[i];
    for (int i = 0; i < w; i++) cin >> B[i];

    for (int i = 0; i < q; i++) {
        int s, t; cin >> s >> t; --s; --t;
        int best = 0;
        for (int j = 0; j < 4; j++) {
            best = max(best, dp(s, t, j));
        }
        cout << best << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 10 ms 768 KB Output is correct
20 Correct 12 ms 896 KB Output is correct
21 Correct 11 ms 768 KB Output is correct
22 Correct 20 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 10 ms 768 KB Output is correct
20 Correct 12 ms 896 KB Output is correct
21 Correct 11 ms 768 KB Output is correct
22 Correct 20 ms 1280 KB Output is correct
23 Correct 12 ms 1664 KB Output is correct
24 Correct 13 ms 1664 KB Output is correct
25 Correct 13 ms 1792 KB Output is correct
26 Correct 13 ms 1664 KB Output is correct
27 Correct 13 ms 1664 KB Output is correct
28 Correct 1567 ms 8952 KB Output is correct
29 Correct 324 ms 2680 KB Output is correct
30 Correct 4074 ms 12904 KB Output is correct
31 Correct 4785 ms 16116 KB Output is correct
32 Correct 313 ms 2296 KB Output is correct
33 Correct 1576 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 768 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 6 ms 768 KB Output is correct
7 Correct 6 ms 768 KB Output is correct
8 Correct 19 ms 1280 KB Output is correct
9 Correct 17 ms 1280 KB Output is correct
10 Correct 16 ms 1184 KB Output is correct
11 Correct 24 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 10 ms 768 KB Output is correct
20 Correct 12 ms 896 KB Output is correct
21 Correct 11 ms 768 KB Output is correct
22 Correct 20 ms 1280 KB Output is correct
23 Correct 12 ms 1664 KB Output is correct
24 Correct 13 ms 1664 KB Output is correct
25 Correct 13 ms 1792 KB Output is correct
26 Correct 13 ms 1664 KB Output is correct
27 Correct 13 ms 1664 KB Output is correct
28 Correct 1567 ms 8952 KB Output is correct
29 Correct 324 ms 2680 KB Output is correct
30 Correct 4074 ms 12904 KB Output is correct
31 Correct 4785 ms 16116 KB Output is correct
32 Correct 313 ms 2296 KB Output is correct
33 Correct 1576 ms 5112 KB Output is correct
34 Correct 5 ms 768 KB Output is correct
35 Correct 5 ms 768 KB Output is correct
36 Correct 5 ms 768 KB Output is correct
37 Correct 5 ms 768 KB Output is correct
38 Correct 5 ms 768 KB Output is correct
39 Correct 6 ms 768 KB Output is correct
40 Correct 6 ms 768 KB Output is correct
41 Correct 19 ms 1280 KB Output is correct
42 Correct 17 ms 1280 KB Output is correct
43 Correct 16 ms 1184 KB Output is correct
44 Correct 24 ms 1400 KB Output is correct
45 Correct 40 ms 2296 KB Output is correct
46 Correct 38 ms 2228 KB Output is correct
47 Correct 36 ms 2296 KB Output is correct
48 Correct 36 ms 2280 KB Output is correct
49 Correct 36 ms 2296 KB Output is correct
50 Correct 1785 ms 9076 KB Output is correct
51 Correct 1789 ms 9976 KB Output is correct
52 Execution timed out 5028 ms 16660 KB Time limit exceeded
53 Halted 0 ms 0 KB -