QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771307#9520. Concave HullHanoistWA 53ms16112kbC++143.3kb2024-11-22 11:31:382024-11-22 11:31:39

Judging History

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

  • [2024-11-22 11:31:39]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:16112kb
  • [2024-11-22 11:31:38]
  • 提交

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();
    int tt = t;
    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]))){
                        j = (j + 1) % (top + 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])));
                }
                if(tt == 1000 && tt - t == 15) printf("%lld\n",top);
                else 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: 100
Accepted
time: 1ms
memory: 7944kb

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:

40
-1

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 7936kb

input:

10
243
-494423502 -591557038
-493438474 -648991734
-493289308 -656152126
-491185085 -661710614
-489063449 -666925265
-464265894 -709944049
-447472922 -737242534
-415977509 -773788538
-394263365 -797285016
-382728841 -807396819
-373481975 -814685302
-368242265 -818267002
-344482838 -833805545
-279398...

output:

2178418010787347715
1826413114144932145
1651687576234220014
1883871859778998985
2119126281997959892
894016174881844630
2271191316922158910
1998643358049669416
1740474221286618711
1168195646932543192

result:

ok 10 lines

Test #3:

score: -100
Wrong Answer
time: 53ms
memory: 16112kb

input:

1000
125
64661186 -13143076
302828013 -185438065
-418713797 -191594241
430218126 -397441626
354327250 -836704374
149668812 -598584998
311305970 66790541
199720625 -592356787
468137 -584752683
258775829 96211747
-358669612 -134890109
-129221188 -998432368
-277309896 -140056561
356901185 420557649
-51...

output:

1986320445246155278
1900093336073022078
1612088392301142476
2012259136539173407
1819942017252118749
1772230185841892196
1164835025329039520
1527446155241140517
1807368432185303666
1236918659444944569
1306839249967484778
1984123720246784099
1868728080720036006
667458140583450322
8
480407409462759045
...

result:

wrong answer 15th lines differ - expected: '2127932992585026491', found: '8'