답안 #647118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647118 2022-10-01T15:58:42 Z messiuuuuu 유괴 2 (JOI17_abduction2) C++14
44 / 100
1776 ms 17684 KB
///
#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 5e4 + 5;
const ll INF = 1e9 + 5;

int m, n, q;
int a[MAXN], b[MAXN];

void Input()
{
    cin >> m >> n >> q;
    for (int i = 1; i <= m; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
        cin >> b[i];
    a[0] = a[m + 1] = b[0] = b[n + 1] = INF;
}

map<int, int> dp[MAXN][2];

int FindS(int r, int c, bool t)
{
    if (t == 0)
    {
        int i = r - 1;
        for (; a[i] < b[c]; i--);
        return i;
    } else
    {
        int i = c - 1;
        for (; b[i] < a[r]; i--);
        return i;
    }
}

int FindL(int r, int c, bool t)
{
    if (t == 0)
    {
        int i = r + 1;
        for (; a[i] < b[c]; i++);
        return i;
    } else
    {
        int i = c + 1;
        for (; b[i] < a[r]; i++);
        return i;
    }
}

int DP(int r, int c, bool t)
{
    if (r < 1 || r > m || c < 1 || c > n)
        return -1;
    if (dp[r][t].count(c))
        return dp[r][t][c];
    int& res = dp[r][t][c];

    int tmp = t == 0 ? r : c;

    int p1 = FindS(r, c, t);
    int d1 = tmp - p1;

    int p2 = FindL(r, c, t);
    int d2 = p2 - tmp;

    res = max(d1 + (t == 0 ? DP(p1, c, !t) : DP(r, p1, !t)), d2 + (t == 0 ? DP(p2, c, !t) : DP(r, p2, !t)));
    return res;
}

void Solve()
{
    while (q-- > 0)
    {
        int s, t;
        cin >> s >> t;
        cout << max(DP(s, t, 0), DP(s, t, 1)) << '\n';
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(task".INP","r"))
    {
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    Input();
    Solve();
}

Compilation message

abduction2.cpp: In function 'int main()':
abduction2.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4916 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4972 KB Output is correct
8 Correct 2 ms 5028 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4916 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4972 KB Output is correct
8 Correct 2 ms 5028 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 5 ms 5076 KB Output is correct
14 Correct 5 ms 5072 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 4 ms 5076 KB Output is correct
17 Correct 4 ms 5044 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 5 ms 5204 KB Output is correct
20 Correct 6 ms 5332 KB Output is correct
21 Correct 5 ms 5200 KB Output is correct
22 Correct 7 ms 5460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4916 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4972 KB Output is correct
8 Correct 2 ms 5028 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 5 ms 5076 KB Output is correct
14 Correct 5 ms 5072 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 4 ms 5076 KB Output is correct
17 Correct 4 ms 5044 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 5 ms 5204 KB Output is correct
20 Correct 6 ms 5332 KB Output is correct
21 Correct 5 ms 5200 KB Output is correct
22 Correct 7 ms 5460 KB Output is correct
23 Correct 13 ms 6356 KB Output is correct
24 Correct 14 ms 6356 KB Output is correct
25 Correct 13 ms 6264 KB Output is correct
26 Correct 13 ms 6288 KB Output is correct
27 Correct 16 ms 6336 KB Output is correct
28 Correct 440 ms 10892 KB Output is correct
29 Correct 98 ms 6920 KB Output is correct
30 Correct 1042 ms 11412 KB Output is correct
31 Correct 1212 ms 12936 KB Output is correct
32 Correct 90 ms 6608 KB Output is correct
33 Correct 415 ms 7964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5204 KB Output is correct
2 Correct 4 ms 5204 KB Output is correct
3 Correct 5 ms 5204 KB Output is correct
4 Correct 4 ms 5204 KB Output is correct
5 Correct 4 ms 5204 KB Output is correct
6 Correct 5 ms 5300 KB Output is correct
7 Correct 5 ms 5204 KB Output is correct
8 Correct 7 ms 5332 KB Output is correct
9 Correct 6 ms 5460 KB Output is correct
10 Correct 6 ms 5332 KB Output is correct
11 Correct 7 ms 5460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4916 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4972 KB Output is correct
8 Correct 2 ms 5028 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 5 ms 5076 KB Output is correct
14 Correct 5 ms 5072 KB Output is correct
15 Correct 3 ms 5076 KB Output is correct
16 Correct 4 ms 5076 KB Output is correct
17 Correct 4 ms 5044 KB Output is correct
18 Correct 3 ms 5076 KB Output is correct
19 Correct 5 ms 5204 KB Output is correct
20 Correct 6 ms 5332 KB Output is correct
21 Correct 5 ms 5200 KB Output is correct
22 Correct 7 ms 5460 KB Output is correct
23 Correct 13 ms 6356 KB Output is correct
24 Correct 14 ms 6356 KB Output is correct
25 Correct 13 ms 6264 KB Output is correct
26 Correct 13 ms 6288 KB Output is correct
27 Correct 16 ms 6336 KB Output is correct
28 Correct 440 ms 10892 KB Output is correct
29 Correct 98 ms 6920 KB Output is correct
30 Correct 1042 ms 11412 KB Output is correct
31 Correct 1212 ms 12936 KB Output is correct
32 Correct 90 ms 6608 KB Output is correct
33 Correct 415 ms 7964 KB Output is correct
34 Correct 4 ms 5204 KB Output is correct
35 Correct 4 ms 5204 KB Output is correct
36 Correct 5 ms 5204 KB Output is correct
37 Correct 4 ms 5204 KB Output is correct
38 Correct 4 ms 5204 KB Output is correct
39 Correct 5 ms 5300 KB Output is correct
40 Correct 5 ms 5204 KB Output is correct
41 Correct 7 ms 5332 KB Output is correct
42 Correct 6 ms 5460 KB Output is correct
43 Correct 6 ms 5332 KB Output is correct
44 Correct 7 ms 5460 KB Output is correct
45 Correct 24 ms 6568 KB Output is correct
46 Correct 21 ms 6592 KB Output is correct
47 Correct 23 ms 6584 KB Output is correct
48 Correct 21 ms 6600 KB Output is correct
49 Correct 18 ms 6528 KB Output is correct
50 Correct 501 ms 10164 KB Output is correct
51 Correct 492 ms 10704 KB Output is correct
52 Correct 1500 ms 14300 KB Output is correct
53 Correct 1400 ms 13996 KB Output is correct
54 Correct 1367 ms 13688 KB Output is correct
55 Incorrect 1776 ms 17684 KB Output isn't correct
56 Halted 0 ms 0 KB -