답안 #289976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289976 2020-09-03T09:28:11 Z gs18115 함박 스테이크 (JOI20_hamburg) C++14
21 / 100
3000 ms 14224 KB
#include<iostream>
#include<vector>
#include<random>
#include<ctime>
#include<tuple>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
inline bool check(const pair<pi,pi>&sq,const pi&p)
{
    return sq.fi.fi<=p.fi&&p.fi<=sq.fi.se&&sq.se.fi<=p.se&&p.se<=sq.se.se;
}
inline pi get1(const vector<pair<pi,pi> >&v)
{
    int xmx=-inf,ymx=-inf;
    for(auto&t:v)
        xmx=max(xmx,t.fi.fi),ymx=max(ymx,t.se.fi);
    return pi(xmx,ymx);
}
inline pair<pi,pi>get2(const vector<pair<pi,pi> >&v)
{
    int xmx=-inf,xmn=inf,ymx=-inf,ymn=inf;
    for(auto&t:v)
        xmx=max(xmx,t.fi.fi),ymx=max(ymx,t.se.fi),
        xmn=min(xmn,t.fi.se),ymn=min(ymn,t.se.se);
    pi p[4]={pi(xmx,ymx),pi(xmx,ymn),pi(xmn,ymn),pi(xmn,ymx)};
    for(int i=0;i<2;i++)
    {
        int j=i+2;
        bool f=1;
        for(auto&t:v)
        {
            if(!check(t,p[i])&&!check(t,p[j]))
            {
                f=0;
                break;
            }
        }
        if(f)
            return pair<pi,pi>(p[i],p[j]);
    }
    return pair<pi,pi>(pi(-1,-1),pi(-1,-1));
}
tuple<pi,pi,pi>get3(const vector<pair<pi,pi> >&v)
{
    int xmx=-inf,xmn=inf,ymx=-inf,ymn=inf;
    for(auto&t:v)
        xmx=max(xmx,t.fi.fi),ymx=max(ymx,t.se.fi),
        xmn=min(xmn,t.fi.se),ymn=min(ymn,t.se.se);
    vector<pi>pv({pi(xmx,ymx),pi(xmx,ymn),pi(xmn,ymx),pi(xmn,ymn)});
    for(pi&p:pv)
    {
        vector<pair<pi,pi> >nxv;
        for(auto&t:v)
            if(!check(t,p))
                nxv.eb(t);
        auto cget=get2(nxv);
        if(cget.fi.fi!=-1)
            return tuple<pi,pi,pi>(p,cget.fi,cget.se);
    }
    return tuple<pi,pi,pi>(pi(-1,-1),pi(-1,-1),pi(-1,-1));
}
tuple<pi,pi,pi,pi>get4(const vector<pair<pi,pi> >&v)
{
    int xmx=-inf,xmn=inf,ymx=-inf,ymn=inf;
    for(auto&t:v)
        xmx=max(xmx,t.fi.fi),ymx=max(ymx,t.se.fi),
        xmn=min(xmn,t.fi.se),ymn=min(ymn,t.se.se);
    vector<pi>pv({pi(xmx,ymx),pi(xmx,ymn),pi(xmn,ymx),pi(xmn,ymn)});
    for(pi&p:pv)
    {
        vector<pair<pi,pi> >nxv;
        for(auto&t:v)
            if(!check(t,p))
                nxv.eb(t);
        auto cget=get3(nxv);
        if(get<0>(cget).fi!=-1)
            return tuple<pi,pi,pi,pi>(p,get<0>(cget),get<1>(cget),get<2>(cget));
    }
    return tuple<pi,pi,pi,pi>(pi(-1,-1),pi(-1,-1),pi(-1,-1),pi(-1,-1));
}
tuple<pi,pi,pi,pi>get4_rand(const vector<pair<pi,pi> >&v)
{
    int xmx=-inf,xmn=inf,ymx=-inf,ymn=inf;
    for(auto&t:v)
        xmx=max(xmx,t.fi.fi),ymx=max(ymx,t.se.fi),
        xmn=min(xmn,t.fi.se),ymn=min(ymn,t.se.se);
    vector<pi>pv;
    for(auto&t:v)
        if(t.fi.fi<=xmn)
            pv.eb(xmn,t.se.fi);
    mt19937 gen(time(NULL));
    for(int i=0;i<(int)pv.size();i++)
        swap(pv[i],pv[i+gen()%((int)pv.size()-i)]);
    for(pi&p:pv)
    {
        vector<pair<pi,pi> >nxv;
        for(auto&t:v)
            if(!check(t,p))
                nxv.eb(t);
        auto cget=get3(nxv);
        if(get<0>(cget).fi!=-1)
            return tuple<pi,pi,pi,pi>(p,get<0>(cget),get<1>(cget),get<2>(cget));
    }
    return tuple<pi,pi,pi,pi>(pi(-1,-1),pi(-1,-1),pi(-1,-1),pi(-1,-1));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    vector<pair<pi,pi> >v(n);
    for(auto&t:v)
        cin>>t.fi.fi>>t.se.fi>>t.fi.se>>t.se.se;
    if(k==1)
    {
        pi ans=get1(v);
        cout<<ans.fi<<' '<<ans.se<<endl;
        return 0;
    }
    if(k==2)
    {
        auto ans=get2(v);
        cout<<ans.fi.fi<<' '<<ans.fi.se<<' '<<ans.se.fi<<' '<<ans.se.se<<endl;
        return 0;
    }
    if(k==3)
    {
        auto ans=get3(v);
        cout<<get<0>(ans).fi<<' '<<get<0>(ans).se<<endl;
        cout<<get<1>(ans).fi<<' '<<get<1>(ans).se<<endl;
        cout<<get<2>(ans).fi<<' '<<get<2>(ans).se<<endl;
        return 0;
    }
    {
        auto ans=get4(v);
        if(get<0>(ans).fi!=-1)
        {
            cout<<get<0>(ans).fi<<' '<<get<0>(ans).se<<endl;
            cout<<get<1>(ans).fi<<' '<<get<1>(ans).se<<endl;
            cout<<get<2>(ans).fi<<' '<<get<2>(ans).se<<endl;
            cout<<get<3>(ans).fi<<' '<<get<3>(ans).se<<endl;
            return 0;
        }
    }
    auto ans=get4_rand(v);
    cout<<get<0>(ans).fi<<' '<<get<0>(ans).se<<endl;
    cout<<get<1>(ans).fi<<' '<<get<1>(ans).se<<endl;
    cout<<get<2>(ans).fi<<' '<<get<2>(ans).se<<endl;
    cout<<get<3>(ans).fi<<' '<<get<3>(ans).se<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 3 ms 404 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 416 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 81 ms 512 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 4 ms 512 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 452 KB Output is correct
20 Correct 28 ms 512 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 33 ms 512 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 424 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 67 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 21 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 24 ms 512 KB Output is correct
36 Correct 27 ms 512 KB Output is correct
37 Correct 54 ms 512 KB Output is correct
38 Correct 40 ms 512 KB Output is correct
39 Correct 37 ms 512 KB Output is correct
40 Correct 91 ms 512 KB Output is correct
41 Correct 26 ms 512 KB Output is correct
42 Correct 60 ms 512 KB Output is correct
43 Correct 95 ms 544 KB Output is correct
44 Correct 30 ms 520 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 43 ms 632 KB Output is correct
47 Correct 12 ms 512 KB Output is correct
48 Correct 20 ms 512 KB Output is correct
49 Correct 75 ms 540 KB Output is correct
50 Correct 15 ms 512 KB Output is correct
51 Correct 62 ms 528 KB Output is correct
52 Correct 42 ms 540 KB Output is correct
53 Correct 21 ms 512 KB Output is correct
54 Correct 43 ms 512 KB Output is correct
55 Correct 26 ms 512 KB Output is correct
56 Correct 40 ms 512 KB Output is correct
57 Correct 89 ms 512 KB Output is correct
58 Correct 32 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 95 ms 3520 KB Output is correct
6 Correct 113 ms 3456 KB Output is correct
7 Correct 92 ms 3576 KB Output is correct
8 Correct 94 ms 3576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 103 ms 3524 KB Output is correct
6 Correct 123 ms 3456 KB Output is correct
7 Correct 103 ms 3456 KB Output is correct
8 Correct 106 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 3 ms 404 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 115 ms 5692 KB Output is correct
14 Correct 99 ms 5616 KB Output is correct
15 Correct 101 ms 5616 KB Output is correct
16 Correct 94 ms 5696 KB Output is correct
17 Correct 102 ms 5692 KB Output is correct
18 Correct 96 ms 4676 KB Output is correct
19 Correct 103 ms 7660 KB Output is correct
20 Correct 134 ms 9996 KB Output is correct
21 Correct 98 ms 7700 KB Output is correct
22 Correct 110 ms 7660 KB Output is correct
23 Correct 106 ms 7660 KB Output is correct
24 Correct 111 ms 7740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 416 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 81 ms 512 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 4 ms 512 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 452 KB Output is correct
20 Correct 28 ms 512 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 33 ms 512 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 424 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 67 ms 512 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 21 ms 512 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 24 ms 512 KB Output is correct
36 Correct 27 ms 512 KB Output is correct
37 Correct 54 ms 512 KB Output is correct
38 Correct 40 ms 512 KB Output is correct
39 Correct 37 ms 512 KB Output is correct
40 Correct 91 ms 512 KB Output is correct
41 Correct 26 ms 512 KB Output is correct
42 Correct 60 ms 512 KB Output is correct
43 Correct 95 ms 544 KB Output is correct
44 Correct 30 ms 520 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 43 ms 632 KB Output is correct
47 Correct 12 ms 512 KB Output is correct
48 Correct 20 ms 512 KB Output is correct
49 Correct 75 ms 540 KB Output is correct
50 Correct 15 ms 512 KB Output is correct
51 Correct 62 ms 528 KB Output is correct
52 Correct 42 ms 540 KB Output is correct
53 Correct 21 ms 512 KB Output is correct
54 Correct 43 ms 512 KB Output is correct
55 Correct 26 ms 512 KB Output is correct
56 Correct 40 ms 512 KB Output is correct
57 Correct 89 ms 512 KB Output is correct
58 Correct 32 ms 512 KB Output is correct
59 Correct 126 ms 7660 KB Output is correct
60 Correct 103 ms 8512 KB Output is correct
61 Correct 99 ms 7744 KB Output is correct
62 Correct 101 ms 7916 KB Output is correct
63 Correct 107 ms 7660 KB Output is correct
64 Correct 114 ms 4600 KB Output is correct
65 Correct 105 ms 7784 KB Output is correct
66 Correct 157 ms 11832 KB Output is correct
67 Correct 140 ms 9604 KB Output is correct
68 Correct 182 ms 12496 KB Output is correct
69 Correct 178 ms 13476 KB Output is correct
70 Correct 152 ms 12132 KB Output is correct
71 Correct 99 ms 9064 KB Output is correct
72 Execution timed out 3024 ms 14224 KB Time limit exceeded
73 Halted 0 ms 0 KB -