답안 #363966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
363966 2021-02-07T17:27:33 Z denkendoemeer Golf (JOI17_golf) C++14
100 / 100
3926 ms 574712 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=1e9;
struct rec
{
    int tip,x,l,r;
    rec(int t,int y,int a,int b):tip(t),x(y),l(a),r(b){}
};
struct comp
{
    vector<int>aux;
    void add(int x)
    {
        aux.push_back(x);
    }
    void build()
    {
        sort(aux.begin(),aux.end());
        aux.erase(unique(aux.begin(),aux.end()),aux.end());
    }
    int poz(int x)
    {
        return lower_bound(aux.begin(),aux.end(),x)-aux.begin()+1;
    }
    int sz()
    {
        return aux.size();
    }
}x3,y3;
bool ok[400005];
int dist[400005];
queue<int>q;
struct ain
{
    set<pair<int,int>>aint[800005];
    ain(){}
    void add(int nod,int st,int dr,int poz)
    {
        st+=400000;
        dr+=400000;
        while(st<=dr){
            if (st%2==1)
                aint[st++].insert({nod,poz});
            if (dr%2==0)
                aint[dr--].insert({nod,poz});
            st=st/2;
            dr=dr/2;
        }
    }
    void rem(int nod,int st,int dr,int poz)
    {
        nod+=400000;
        while(nod){
            for(auto it=aint[nod].lower_bound({st,-inf});it!=aint[nod].end() && it->first<=dr;aint[nod].erase(it++)){
                int nr=it->second;
                if (ok[nr]==0){
                    ok[nr]=1;
                    dist[nr]=poz+1;
                    q.push(nr);
                }
            }
            nod=nod/2;
        }
    }
}ai[2];
vector<rec>r;
int xa[100005],ya[100005],xb[100005],yb[100005];
vector<pair<int,int>>add[400005],del[400005];
vector<int>fir,last;
int n,sx,sy,ex,ey;
void build(int tip)
{
    int i;
    for(i=1;i<=n;i++)
    add[xa[i]].push_back({ya[i],yb[i]}),del[xb[i]].push_back({ya[i],yb[i]});
    set<pair<int,int>>st;
    st.insert({1,1});
    st.insert({y3.sz(),y3.sz()});
    for(i=1;i<=x3.sz();i++){
        for(auto it:del[i]){
            auto it2=st.find(it),l=it2,dr=it2;
            l--;
            dr++;
            r.push_back(rec(tip,i,l->second,dr->first));
            st.erase(it2);
        }
        if (sx==i){
            auto it=st.lower_bound({sy,-inf}),st=it;
            st--;
            fir.push_back(r.size());
            r.push_back(rec(tip,i,st->second,it->first));
        }
        if (ex==i){
            auto it=st.lower_bound({ey,-inf}),st=it;
            st--;
            last.push_back(r.size());
            r.push_back(rec(tip,i,st->second,it->first));
        }
        for(auto it:add[i]){
            st.insert(it);
            auto it2=st.find(it),st=it2,dr=it2;
            st--;
            dr++;
            r.push_back(rec(tip,i,st->second,dr->first));
        }
    }
    for(i=1;i<=x3.sz();i++)
        add[i].clear(),del[i].clear();
    for(i=1;i<=n;i++)
        swap(xa[i],ya[i]),swap(xb[i],yb[i]);
    swap(sx,sy);
    swap(ex,ey);
    swap(x3,y3);
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int i;
    scanf("%d%d%d%d%d",&sx,&sy,&ex,&ey,&n);
    x3.add(0);
    x3.add(inf);
    x3.add(sx);
    x3.add(ex);
    y3.add(0);
    y3.add(inf);
    y3.add(sy);
    y3.add(ey);
    for(i=1;i<=n;i++)
        scanf("%d%d%d%d",&xa[i],&xb[i],&ya[i],&yb[i]),x3.add(xa[i]),x3.add(xb[i]),y3.add(ya[i]),y3.add(yb[i]);
    x3.build();
    y3.build();
    sx=x3.poz(sx);
    ex=x3.poz(ex);
    sy=y3.poz(sy);
    ey=y3.poz(ey);
    for(i=1;i<=n;i++)
        xa[i]=x3.poz(xa[i]),xb[i]=x3.poz(xb[i]),ya[i]=y3.poz(ya[i]),yb[i]=y3.poz(yb[i]);
    build(0);
    build(1);
    for(i=0;i<r.size();i++)
        ai[r[i].tip].add(r[i].x,r[i].l,r[i].r,i);
    for(auto it:fir){
        if (r[it].tip==0){
            if (ex==r[it].x && ey>=r[it].l && ey<=r[it].r){
                printf("1\n");
                return 0;
            }
        }
        else{
            if (ey==r[it].x && ex>=r[it].l && ex<=r[it].r){
                printf("1\n");
                return 0;
            }
        }
        q.push(it);
        ok[it]=1;
    }
    while(q.size()){
        int nod=q.front();
        q.pop();
        ai[1-r[nod].tip].rem(r[nod].x,r[nod].l,r[nod].r,dist[nod]);
    }
    int ans=inf;
    for(auto it:last)
        if (ok[it])
            ans=min(ans,dist[it]);
    printf("%d\n",ans+1);
return 0;
}

Compilation message

golf.cpp: In function 'int main()':
golf.cpp:142:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<rec>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  142 |     for(i=0;i<r.size();i++)
      |             ~^~~~~~~~~
golf.cpp:121:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  121 |     scanf("%d%d%d%d%d",&sx,&sy,&ex,&ey,&n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
golf.cpp:131:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  131 |         scanf("%d%d%d%d",&xa[i],&xb[i],&ya[i],&yb[i]),x3.add(xa[i]),x3.add(xb[i]),y3.add(ya[i]),y3.add(yb[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 94316 KB Output is correct
2 Correct 62 ms 94316 KB Output is correct
3 Correct 62 ms 94336 KB Output is correct
4 Correct 62 ms 94572 KB Output is correct
5 Correct 69 ms 95468 KB Output is correct
6 Correct 69 ms 95488 KB Output is correct
7 Correct 72 ms 95596 KB Output is correct
8 Correct 71 ms 95468 KB Output is correct
9 Correct 77 ms 95596 KB Output is correct
10 Correct 68 ms 95468 KB Output is correct
11 Correct 68 ms 95520 KB Output is correct
12 Correct 69 ms 95468 KB Output is correct
13 Correct 75 ms 95468 KB Output is correct
14 Correct 70 ms 95468 KB Output is correct
15 Correct 65 ms 94828 KB Output is correct
16 Correct 69 ms 95468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 94316 KB Output is correct
2 Correct 62 ms 94316 KB Output is correct
3 Correct 62 ms 94336 KB Output is correct
4 Correct 62 ms 94572 KB Output is correct
5 Correct 69 ms 95468 KB Output is correct
6 Correct 69 ms 95488 KB Output is correct
7 Correct 72 ms 95596 KB Output is correct
8 Correct 71 ms 95468 KB Output is correct
9 Correct 77 ms 95596 KB Output is correct
10 Correct 68 ms 95468 KB Output is correct
11 Correct 68 ms 95520 KB Output is correct
12 Correct 69 ms 95468 KB Output is correct
13 Correct 75 ms 95468 KB Output is correct
14 Correct 70 ms 95468 KB Output is correct
15 Correct 65 ms 94828 KB Output is correct
16 Correct 69 ms 95468 KB Output is correct
17 Correct 72 ms 95724 KB Output is correct
18 Correct 70 ms 95876 KB Output is correct
19 Correct 70 ms 95724 KB Output is correct
20 Correct 70 ms 95944 KB Output is correct
21 Correct 71 ms 95852 KB Output is correct
22 Correct 73 ms 95852 KB Output is correct
23 Correct 79 ms 95852 KB Output is correct
24 Correct 71 ms 95852 KB Output is correct
25 Correct 71 ms 95724 KB Output is correct
26 Correct 72 ms 95852 KB Output is correct
27 Correct 65 ms 94976 KB Output is correct
28 Correct 69 ms 95596 KB Output is correct
29 Correct 67 ms 95724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 94316 KB Output is correct
2 Correct 62 ms 94316 KB Output is correct
3 Correct 62 ms 94336 KB Output is correct
4 Correct 62 ms 94572 KB Output is correct
5 Correct 69 ms 95468 KB Output is correct
6 Correct 69 ms 95488 KB Output is correct
7 Correct 72 ms 95596 KB Output is correct
8 Correct 71 ms 95468 KB Output is correct
9 Correct 77 ms 95596 KB Output is correct
10 Correct 68 ms 95468 KB Output is correct
11 Correct 68 ms 95520 KB Output is correct
12 Correct 69 ms 95468 KB Output is correct
13 Correct 75 ms 95468 KB Output is correct
14 Correct 70 ms 95468 KB Output is correct
15 Correct 65 ms 94828 KB Output is correct
16 Correct 69 ms 95468 KB Output is correct
17 Correct 72 ms 95724 KB Output is correct
18 Correct 70 ms 95876 KB Output is correct
19 Correct 70 ms 95724 KB Output is correct
20 Correct 70 ms 95944 KB Output is correct
21 Correct 71 ms 95852 KB Output is correct
22 Correct 73 ms 95852 KB Output is correct
23 Correct 79 ms 95852 KB Output is correct
24 Correct 71 ms 95852 KB Output is correct
25 Correct 71 ms 95724 KB Output is correct
26 Correct 72 ms 95852 KB Output is correct
27 Correct 65 ms 94976 KB Output is correct
28 Correct 69 ms 95596 KB Output is correct
29 Correct 67 ms 95724 KB Output is correct
30 Correct 3366 ms 303032 KB Output is correct
31 Correct 3522 ms 303092 KB Output is correct
32 Correct 3435 ms 309368 KB Output is correct
33 Correct 3487 ms 308540 KB Output is correct
34 Correct 3746 ms 308596 KB Output is correct
35 Correct 3402 ms 309668 KB Output is correct
36 Correct 3544 ms 309704 KB Output is correct
37 Correct 3408 ms 311068 KB Output is correct
38 Correct 3370 ms 309316 KB Output is correct
39 Correct 3385 ms 309576 KB Output is correct
40 Correct 2840 ms 451648 KB Output is correct
41 Correct 3076 ms 469664 KB Output is correct
42 Correct 3876 ms 566572 KB Output is correct
43 Correct 3926 ms 574712 KB Output is correct
44 Correct 3428 ms 523844 KB Output is correct
45 Correct 3741 ms 562100 KB Output is correct
46 Correct 3671 ms 553004 KB Output is correct
47 Correct 3723 ms 551436 KB Output is correct
48 Correct 3580 ms 543248 KB Output is correct
49 Correct 3715 ms 554152 KB Output is correct
50 Correct 70 ms 95596 KB Output is correct
51 Correct 69 ms 95596 KB Output is correct
52 Correct 69 ms 95596 KB Output is correct