답안 #410505

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410505 2021-05-22T20:33:13 Z duality 유괴 2 (JOI17_abduction2) C++11
44 / 100
3612 ms 16516 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int H,W;
int A[50000],B[50000];
map<pii,int> dp;
int findAns(int x,int y) {
    if ((x < 0) || (x >= W) || (y < 0) || (y >= H)) return -1;
    else if (dp.count(mp(x,y))) return dp[mp(x,y)];

    int i,ans;
    if (A[y] < B[x]) {
        for (i = y; i >= 0; i--) {
            if (A[i] > B[x]) break;
        }
        ans = findAns(x,i)+abs(i-y);
        for (i = y; i < H; i++) {
            if (A[i] > B[x]) break;
        }
        ans = max(ans,findAns(x,i)+abs(i-y));
    }
    else {
        for (i = x; i >= 0; i--) {
            if (B[i] > A[y]) break;
        }
        ans = findAns(i,y)+abs(i-x);
        for (i = x; i < W; i++) {
            if (B[i] > A[y]) break;
        }
        ans = max(ans,findAns(i,y)+abs(i-x));
    }
    dp[mp(x,y)] = ans;
    return ans;
}
int main() {
    int i,j;
    int Q,S,T;
    scanf("%d %d %d",&H,&W,&Q);
    for (i = 0; i < H; i++) scanf("%d",&A[i]);
    for (i = 0; i < W; i++) scanf("%d",&B[i]);
    for (i = 0; i < Q; i++) {
        scanf("%d %d",&S,&T);
        S--,T--;

        int ans = 0;
        for (j = S-1; j >= 0; j--) {
            if (A[j] > B[T]) break;
        }
        ans = max(ans,findAns(T,j)+abs(j-S));
        for (j = S+1; j < H; j++) {
            if (A[j] > B[T]) break;
        }
        ans = max(ans,findAns(T,j)+abs(j-S));
        for (j = T-1; j >= 0; j--) {
            if (B[j] > A[S]) break;
        }
        ans = max(ans,findAns(j,S)+abs(j-T));
        for (j = T+1; j < W; j++) {
            if (B[j] > A[S]) break;
        }
        ans = max(ans,findAns(j,S)+abs(j-T));
        printf("%d\n",ans);
    }

    return 0;
}

Compilation message

abduction2.cpp: In function 'int main()':
abduction2.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |     scanf("%d %d %d",&H,&W,&Q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
abduction2.cpp:93:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |     for (i = 0; i < H; i++) scanf("%d",&A[i]);
      |                             ~~~~~^~~~~~~~~~~~
abduction2.cpp:94:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |     for (i = 0; i < W; i++) scanf("%d",&B[i]);
      |                             ~~~~~^~~~~~~~~~~~
abduction2.cpp:96:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         scanf("%d %d",&S,&T);
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 316 KB Output is correct
19 Correct 5 ms 460 KB Output is correct
20 Correct 7 ms 588 KB Output is correct
21 Correct 6 ms 588 KB Output is correct
22 Correct 9 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 316 KB Output is correct
19 Correct 5 ms 460 KB Output is correct
20 Correct 7 ms 588 KB Output is correct
21 Correct 6 ms 588 KB Output is correct
22 Correct 9 ms 756 KB Output is correct
23 Correct 16 ms 1612 KB Output is correct
24 Correct 20 ms 1660 KB Output is correct
25 Correct 15 ms 1592 KB Output is correct
26 Correct 15 ms 1612 KB Output is correct
27 Correct 21 ms 1608 KB Output is correct
28 Correct 543 ms 7300 KB Output is correct
29 Correct 121 ms 2372 KB Output is correct
30 Correct 1939 ms 8104 KB Output is correct
31 Correct 2230 ms 10028 KB Output is correct
32 Correct 155 ms 1868 KB Output is correct
33 Correct 715 ms 3704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 444 KB Output is correct
2 Correct 3 ms 476 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 9 ms 740 KB Output is correct
9 Correct 9 ms 824 KB Output is correct
10 Correct 11 ms 716 KB Output is correct
11 Correct 11 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 316 KB Output is correct
19 Correct 5 ms 460 KB Output is correct
20 Correct 7 ms 588 KB Output is correct
21 Correct 6 ms 588 KB Output is correct
22 Correct 9 ms 756 KB Output is correct
23 Correct 16 ms 1612 KB Output is correct
24 Correct 20 ms 1660 KB Output is correct
25 Correct 15 ms 1592 KB Output is correct
26 Correct 15 ms 1612 KB Output is correct
27 Correct 21 ms 1608 KB Output is correct
28 Correct 543 ms 7300 KB Output is correct
29 Correct 121 ms 2372 KB Output is correct
30 Correct 1939 ms 8104 KB Output is correct
31 Correct 2230 ms 10028 KB Output is correct
32 Correct 155 ms 1868 KB Output is correct
33 Correct 715 ms 3704 KB Output is correct
34 Correct 3 ms 444 KB Output is correct
35 Correct 3 ms 476 KB Output is correct
36 Correct 3 ms 460 KB Output is correct
37 Correct 3 ms 460 KB Output is correct
38 Correct 3 ms 460 KB Output is correct
39 Correct 3 ms 588 KB Output is correct
40 Correct 3 ms 468 KB Output is correct
41 Correct 9 ms 740 KB Output is correct
42 Correct 9 ms 824 KB Output is correct
43 Correct 11 ms 716 KB Output is correct
44 Correct 11 ms 844 KB Output is correct
45 Correct 28 ms 1892 KB Output is correct
46 Correct 25 ms 1916 KB Output is correct
47 Correct 25 ms 1824 KB Output is correct
48 Correct 25 ms 1848 KB Output is correct
49 Correct 25 ms 1972 KB Output is correct
50 Correct 627 ms 6512 KB Output is correct
51 Correct 657 ms 7168 KB Output is correct
52 Correct 2525 ms 12132 KB Output is correct
53 Correct 2538 ms 11832 KB Output is correct
54 Correct 2419 ms 11452 KB Output is correct
55 Incorrect 3612 ms 16516 KB Output isn't correct
56 Halted 0 ms 0 KB -