답안 #233004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233004 2020-05-18T22:16:21 Z thebes 유괴 2 (JOI17_abduction2) C++14
44 / 100
234 ms 20120 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef vector<int> vi;
#define F first
#define S second
#define pb push_back
#define mt make_tuple

const int MN = 1e5+5;
int N, M, Q, i, j, x, y, dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
map<tuple<int,int,int>,int> dp; vi a, b;

struct MaxSegmentTree{
    int st[2*MN], n;
    void build(int i,int s,int e,vi &vec){
        if(s!=e){
            build(2*i,s,(s+e)/2,vec);
            build(2*i+1,(s+e)/2+1,e,vec);
            st[i]=max(st[2*i],st[2*i+1]);
        }
        else st[i]=vec[s];
    }
    void init(vi vec){
        n = (int)vec.size();
        build(1,0,n-1,vec);
    }
    int lquery(int i,int s,int e,int ss,int se,int val){
        if(ss>se) return -1;
        if(s>=ss&&e<=se){
            if(st[i]<=val) return -1;
            else if(s==e) return e;
        }
        else if((s+e)/2<ss) return lquery(2*i+1,(s+e)/2+1,e,ss,se,val);
        else if((s+e)/2>=se) return lquery(2*i,s,(s+e)/2,ss,se,val);
        int r = lquery(2*i+1,(s+e)/2+1,e,ss,se,val);
        return r==-1?lquery(2*i,s,(s+e)/2,ss,se,val):r;
    }
    int lquery(int idx,int val){
        return lquery(1,0,n-1,0,idx-1,val);
    }
    int rquery(int i,int s,int e,int ss,int se,int val){
        if(ss>se) return -1;
        if(s>=ss&&e<=se){
            if(st[i]<=val) return -1;
            else if(s==e) return s;
        }
        else if((s+e)/2<ss) return rquery(2*i+1,(s+e)/2+1,e,ss,se,val);
        else if((s+e)/2>=se) return rquery(2*i,s,(s+e)/2,ss,se,val);
        int r = rquery(2*i,s,(s+e)/2,ss,se,val);
        return r==-1?rquery(2*i+1,(s+e)/2+1,e,ss,se,val):r;
    }
    int rquery(int idx,int val){
        return rquery(1,0,n-1,idx+1,n,val);
    }
}R,C;

int solve(int x,int y,int d){
    if(dp.count(mt(x,y,d))) return dp[mt(x,y,d)];
    int ans = 0;
    if(a[x]>b[y]){
        if(d!=0){
            int nxt = C.lquery(y,a[x]);
            if(~nxt) ans=max(ans,y-nxt+solve(x,nxt,1));
            else ans=max(ans,y);
        }
        if(d!=1){
            int nxt = C.rquery(y,a[x]);
            if(~nxt) ans=max(ans,nxt-y+solve(x,nxt,0));
            else ans=max(ans,M-1-y);
        }
    }
    else{
        if(d!=2){
            int nxt = R.lquery(x,b[y]);
            if(~nxt) ans=max(ans,x-nxt+solve(nxt,y,3));
            else ans=max(ans,x);
        }
        if(d!=3){
            int nxt = R.rquery(x,b[y]);
            if(~nxt) ans=max(ans,nxt-x+solve(nxt,y,2));
            else ans=max(ans,N-1-x);
        }
    }
    return dp[mt(x,y,d)]=ans;
}

int main(){
    scanf("%d%d%d",&N,&M,&Q);
    for(i=1;i<=N;i++){
        scanf("%d",&x);
        a.pb(x);
    }
    for(i=1;i<=M;i++){
        scanf("%d",&x);
        b.pb(x);
    }
    R.init(a), C.init(b);
    for(;Q;Q--){
        scanf("%d%d",&x,&y);
        //dp.clear();
        int sna = 0;
        for(i=0;i<4;i++){
            int nx=x+dx[i], ny=y+dy[i];
            if(nx<1||nx>N||ny<1||ny>M) continue;
            sna=max(sna,solve(nx-1,ny-1,i)+1);
        }
        printf("%d\n",sna);
    }
    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]
     scanf("%d%d%d",&N,&M,&Q);
     ~~~~~^~~~~~~~~~~~~~~~~~~
abduction2.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x);
         ~~~~~^~~~~~~~~
abduction2.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x);
         ~~~~~^~~~~~~~~
abduction2.cpp:103:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&x,&y);
         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 8 ms 768 KB Output is correct
21 Correct 8 ms 640 KB Output is correct
22 Correct 10 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 8 ms 768 KB Output is correct
21 Correct 8 ms 640 KB Output is correct
22 Correct 10 ms 1024 KB Output is correct
23 Correct 23 ms 2300 KB Output is correct
24 Correct 24 ms 2300 KB Output is correct
25 Correct 23 ms 2300 KB Output is correct
26 Correct 24 ms 2300 KB Output is correct
27 Correct 24 ms 2300 KB Output is correct
28 Correct 41 ms 10992 KB Output is correct
29 Correct 24 ms 3060 KB Output is correct
30 Correct 94 ms 9964 KB Output is correct
31 Correct 117 ms 12524 KB Output is correct
32 Correct 25 ms 2300 KB Output is correct
33 Correct 41 ms 4468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 512 KB Output is correct
2 Correct 8 ms 512 KB Output is correct
3 Correct 8 ms 640 KB Output is correct
4 Correct 9 ms 512 KB Output is correct
5 Correct 8 ms 512 KB Output is correct
6 Correct 6 ms 768 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 11 ms 896 KB Output is correct
9 Correct 11 ms 896 KB Output is correct
10 Correct 10 ms 896 KB Output is correct
11 Correct 11 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 7 ms 640 KB Output is correct
20 Correct 8 ms 768 KB Output is correct
21 Correct 8 ms 640 KB Output is correct
22 Correct 10 ms 1024 KB Output is correct
23 Correct 23 ms 2300 KB Output is correct
24 Correct 24 ms 2300 KB Output is correct
25 Correct 23 ms 2300 KB Output is correct
26 Correct 24 ms 2300 KB Output is correct
27 Correct 24 ms 2300 KB Output is correct
28 Correct 41 ms 10992 KB Output is correct
29 Correct 24 ms 3060 KB Output is correct
30 Correct 94 ms 9964 KB Output is correct
31 Correct 117 ms 12524 KB Output is correct
32 Correct 25 ms 2300 KB Output is correct
33 Correct 41 ms 4468 KB Output is correct
34 Correct 8 ms 512 KB Output is correct
35 Correct 8 ms 512 KB Output is correct
36 Correct 8 ms 640 KB Output is correct
37 Correct 9 ms 512 KB Output is correct
38 Correct 8 ms 512 KB Output is correct
39 Correct 6 ms 768 KB Output is correct
40 Correct 6 ms 640 KB Output is correct
41 Correct 11 ms 896 KB Output is correct
42 Correct 11 ms 896 KB Output is correct
43 Correct 10 ms 896 KB Output is correct
44 Correct 11 ms 1024 KB Output is correct
45 Correct 28 ms 2300 KB Output is correct
46 Correct 28 ms 2292 KB Output is correct
47 Correct 28 ms 2300 KB Output is correct
48 Correct 28 ms 2300 KB Output is correct
49 Correct 28 ms 2300 KB Output is correct
50 Correct 48 ms 8684 KB Output is correct
51 Correct 50 ms 9836 KB Output is correct
52 Correct 155 ms 13520 KB Output is correct
53 Correct 149 ms 14068 KB Output is correct
54 Correct 145 ms 13840 KB Output is correct
55 Incorrect 234 ms 20120 KB Output isn't correct
56 Halted 0 ms 0 KB -