답안 #932597

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932597 2024-02-23T19:49:40 Z tminh_hk20 SIR (COI15_sir) C++14
100 / 100
335 ms 31520 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
const int N=6e5+5;

struct vec{
    int x, y;
}a[N+10], b[N+10];

vec operator - (vec a, vec b){
    return {a.x-b.x,a.y-b.y};
}

bool operator < (vec a, vec b){
    if (a.x==b.x) return a.y<b.y;
    return a.x<b.x;
}

int cross(vec a, vec b){
    return a.x*b.y-b.x*a.y;
}

int n, m, c, s[N+10];
vector<vec> v;

void convexhull(){
    sort(b+1,b+m+1);

    //upper
    v.push_back(b[1]);
    for (int i=2;i<=m;i++){
        while(v.size()>=2 && cross(b[i]-v[v.size()-1],v[v.size()-2]-v[v.size()-1])>0) v.pop_back();
        v.push_back(b[i]);
    }

    // lower
    for (int i=m-1;i>=1;i--){
        while(v.size()>=2 && cross(b[i]-v[v.size()-1],v[v.size()-2]-v[v.size()-1])>0) v.pop_back();
        v.push_back(b[i]);
    }

    if (v.size()>1) v.pop_back();
}


int get(vec a, vec b, vec c){
    if(a.x==b.x&&a.y==b.y)  return 0;
	return abs(a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y));
}

signed main(){
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i].x>>a[i].y;
    reverse(a,a+n); for (int i=1;i<=n;i++) a[n-1+i] = a[i-1];

    cin>>m;
    for(int i=1;i<=m;i++) cin>>b[i].x>>b[i].y;
    convexhull();

    int j =0; c = v.size();
    for (int i=0;i<c;i++){
        if (cross(v[j]-a[0],v[i]-a[0])<=0){
            j = i;
        }
    }

    int res = 0;
    int far = 1;
    int tmp = 0;
    for (int i=0;i<n;i++){
        while(!(cross(v[j]-a[i],v[(j+1)%c]-a[i])<=0)){
            j++; j%=c;
        }
        while(cross(a[far+1]-a[i],v[j]-a[i])<0) tmp+=get(a[i],a[far],a[far+1]), far++;
        res = max(res, tmp);
//        cout <<i<<" "<<j<<" "<<far<<endl;
        tmp-=get(a[i],a[i+1],a[far]);
    }

    cout <<res<<endl;
}

//>1 4
//>2 4
//>3 0
//>4 1
//>5 3
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 2 ms 4444 KB Output is correct
3 Correct 4 ms 4552 KB Output is correct
4 Correct 2 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 4 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 335 ms 17096 KB Output is correct
2 Correct 294 ms 15816 KB Output is correct
3 Correct 254 ms 20676 KB Output is correct
4 Correct 90 ms 10576 KB Output is correct
5 Correct 240 ms 14896 KB Output is correct
6 Correct 279 ms 31520 KB Output is correct