QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771290#9520. Concave HullHanoistTL 0ms0kbC++143.2kb2024-11-22 11:25:412024-11-22 11:25:41

Judging History

你现在查看的是最新测评结果

  • [2024-11-22 11:25:41]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-22 11:25:41]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<functional>
#include<utility>
#include<cassert>
#include<map>
using namespace std;
inline int read(){
    int x = 0,f = 1;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        x = (x << 3) + (x << 1) + (c ^ 48);
        c = getchar();
    }
    return x * f;
}
const int N = 1e5 + 1;
struct vec{
    long long x,y;
}p[2][N],stak[2][N << 1];
int n,cnt[2],top;
map<pair<int,int>,bool> vis;
bool cmp(vec a,vec b){
    if(a.x != b.x) return a.x < b.x;
    return a.y < b.y;
}
inline long long Cross(vec a,vec b){
    return a.x * b.y - a.y * b.x;
}
inline long long check(vec a,vec b,vec c){
    vec A = (vec){b.x - a.x,b.y - a.y};
    vec B = (vec){c.x - a.x,c.y - a.y};
    return Cross(A,B);
}
void init(int op){
    int i,j,temp;
    sort(p[op] + 1,p[op] + cnt[op] + 1,cmp);
    if(cnt[op] == 1){
        stak[op][0] = p[op][1];
        return;
    }
    stak[op][0] = p[op][1],stak[op][1] = p[op][2];
    top = 1;
    if(cnt[op] == 2) return;
    for(i = 3;i <= cnt[op];i++){
        while(top && check(stak[op][top - 1],stak[op][top],p[op][i]) <= 0) --top;
        stak[op][++top] = p[op][i];
    }
    temp = top;
    stak[op][++top] = p[op][cnt[op] - 1];
    for(i = cnt[op] - 2;i >= 1;i--){
        while(top > temp && check(stak[op][top - 1],stak[op][top],p[op][i]) <= 0) --top;
        stak[op][++top] = p[op][i];
    }
}
int main(){
    int t,i,j,k,x,y;
    t = read();
    while(t--){
        n = read();
        cnt[0] = n,cnt[1] = 0;
        for(i = 1;i <= n;i++) p[0][i].x = read(),p[0][i].y = read();
        init(0);
        int m = top;
        for(i = 0;i <= m;i++){
            vis[{stak[0][i].x,stak[0][i].y}] = 1;
        }
        for(i = 1;i <= n;i++){
            if(!vis[{p[0][i].x,p[0][i].y}]) p[1][++cnt[1]] = p[0][i];
        }
        if(!cnt[1]){
            puts("-1");
        }
        else{
            //for(i = 0;i <= m;i++) printf("%lld %lld?\n",stak[0][i].x,stak[0][i].y);
            long long res = 0;
            for(i = 0;i < m;i++){
                res += abs(check(stak[0][0],stak[0][i],stak[0][i + 1]));
            }
            long long ans = 0;
            init(1);
            //for(i = 0;i <= top;i++) printf("%d %d\n",stak[1][i].x,stak[1][i].y);
            
                for(i = 0,j = 0;i < m;i++){
                    while(abs(check(stak[1][j],stak[0][i],stak[0][i + 1])) > abs(check(stak[1][(j + 1) % (top + 1)],stak[0][i],stak[0][i + 1]))){
                        ans = max(ans,res - abs(check(stak[1][j],stak[0][i],stak[0][i + 1])));                  
                    }
                    ans = max(ans,res - abs(check(stak[1][j],stak[0][i],stak[0][i + 1])));
                }
                printf("%lld\n",ans);
        }
        for(i = 0;i <= m;i++) vis[{stak[0][i].x,stak[0][i].y}] = 0;
        for(i = 0;i <= m + 1;i++) stak[0][i] = (vec){0,0};
        for(i = 0;i <= top + 1;i++) stak[1][i] = (vec){0,0};
    }
    return 0;
}
/*
2
6
-2 0
1 -2
5 2
0 4
1 2
3 1
4
0 0
1 0
0 1
1 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

2
6
-2 0
1 -2
5 2
0 4
1 2
3 1
4
0 0
1 0
0 1
1 1

output:


result: