QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#385704#5111. Take On MemeSolitaryDreamWA 81ms30060kbC++173.1kb2024-04-11 00:03:522024-04-11 00:03:52

Judging History

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

  • [2024-04-11 00:03:52]
  • 评测
  • 测评结果:WA
  • 用时:81ms
  • 内存:30060kb
  • [2024-04-11 00:03:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fs first
#define sd second
const int N=1e4+1e3+7;
struct P {
    int x, y, id;
};
int operator *(const P &a,const P &b)
{
    return a.x*b.y-a.y*b.x;
}
bool operator <(const P &a,const P &b)
{
    int da=a.x>0||(a.x==0&&a.y>0),db=b.x>0||(b.x==0&&b.y>0);
    if(da!=db)
        return da>db;
    return a*b>0;
}
using cv=pair<P, vector<P> >;
cv f[N];
P operator -(const P &a)
{
    return {-a.x,-a.y};
}
P operator -(const P &a,const P &b)
{
    return {a.x-b.x,a.y-b.y};
}
P operator +(const P &a,const P &b)
{
    return {a.x+b.x,a.y+b.y};
}
// cv operator +(const cv &a,const cv &b)
// {

// }
int n;
vector<int> g[N];
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int k;
        cin>>k;
        if(k)
        {
            while(k--)
            {
                int a;
                cin>>a;
                g[i].push_back(a);
            }
        }
        else
        {
            cin>>f[i].fs.x>>f[i].fs.y;
            // f[i].sd.push_back({0,0,i});
        }
    }
    for(int i=n;i>=1;i--)
    {
        if(!g[i].size())
            continue;
        vector<P> all;
        cv tmp;
        for(auto v:g[i])
        {
            tmp.fs=tmp.fs+f[v].fs;
            for(auto p:f[v].sd)
                tmp.sd.push_back(p);
        }
        sort(tmp.sd.begin(),tmp.sd.end());
        for(auto v:g[i])
        {
            vector<P> tv;
            P base=-(tmp.fs-f[v].fs);
            for(auto p:tmp.sd)
                if(p.id!=v)
                {
                    tv.push_back(-p);
                    if(p.x>0||(p.x==0&&p.y>0))
                        base=base-p;
                }
            base=base+f[v].fs;
            int m=tv.size();
            for(auto q:f[v].sd)
                tv.push_back(q);
            sort(tv.begin(),tv.end());
            // inplace_merge(tv.begin(),tv.begin()+m,tv.end());
            all.push_back(base);
            for(auto x:tv)
                base=base+x,all.push_back(base);
        }
        sort(all.begin(),all.end(),[&](const P &a,const P &b){return a.x<b.x||(a.x==b.x&&a.y<b.y);});
        vector<P> st;
        for(auto p:all)
        {
            while(st.size()>1&&(p-st.end()[-2])*(st.back()-st.end()[-2])>=0)
                st.pop_back();
            st.push_back(p);
        }
        int k=st.size();
        reverse(all.begin(),all.end());
        for(auto p:all)
        {
            while(st.size()>k&&(p-st.end()[-2])*(st.back()-st.end()[-2])>=0)
                st.pop_back();
            st.push_back(p);
        }
        st.pop_back();
        f[i].first=st[0];
        for(int t=0;t<st.size();t++)
        {
            f[i].sd.push_back(st[(t+1)%st.size()]-st[t]);
        }
        sort(f[i].sd.begin(),f[i].sd.end());
        for(auto &p:f[i].sd)
            p.id=i;
    }
    int ans=0;
    P base=f[1].fs;
    for(auto x:f[1].sd)
    {
        base=base+x;
        ans=max(ans,base.x*base.x+base.y*base.y);
    }
    cout<<ans<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4440kb

input:

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

output:

725

result:

ok single line: '725'

Test #2:

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

input:

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

output:

340

result:

ok single line: '340'

Test #3:

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

input:

18
3 4 3 2
2 5 6
3 7 9 8
3 10 11 12
0 4 -1
0 18 49
0 -2 10
2 13 14
0 -5 6
0 5 8
4 15 16 17 18
0 17 3
0 3 -9
0 -7 -1
0 14 -33
0 -23 11
0 11 14
0 2 19

output:

26269

result:

ok single line: '26269'

Test #4:

score: 0
Accepted
time: 64ms
memory: 19144kb

input:

10000
59 2 171 340 509 678 847 1016 1185 1382 1551 1720 1889 2058 2227 2396 2565 2734 2903 3072 3241 3410 3579 3748 3917 4086 4255 4424 4593 4762 4931 5100 5269 5438 5607 5776 5945 6114 6283 6452 6621 6790 6959 7128 7297 7466 7635 7804 7973 8142 8311 8480 8649 8818 8987 9156 9325 9494 9663 9832
2 3 ...

output:

4893524000116

result:

ok single line: '4893524000116'

Test #5:

score: 0
Accepted
time: 62ms
memory: 12932kb

input:

10000
37 2 272 542 812 1082 1352 1622 1892 2162 2432 2702 2972 3242 3512 3782 4052 4322 4592 4862 5132 5402 5672 5942 6212 6482 6752 7022 7292 7571 7841 8111 8381 8651 8921 9191 9461 9731
51 3 8 13 18 23 42 47 52 57 62 67 72 77 82 87 92 97 102 107 112 117 122 127 132 137 142 147 152 157 162 167 172 ...

output:

5186192629829

result:

ok single line: '5186192629829'

Test #6:

score: 0
Accepted
time: 81ms
memory: 30060kb

input:

10000
89 2 114 226 338 450 562 674 786 898 1010 1122 1234 1346 1458 1570 1682 1794 1906 2018 2130 2242 2354 2466 2578 2690 2802 2914 3026 3138 3250 3362 3474 3586 3698 3810 3922 4034 4146 4258 4370 4482 4594 4706 4818 4930 5042 5154 5266 5378 5490 5602 5714 5826 5938 6050 6162 6274 6386 6498 6610 67...

output:

5143217930845

result:

ok single line: '5143217930845'

Test #7:

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

input:

1
0 0 0

output:

0

result:

ok single line: '0'

Test #8:

score: -100
Wrong Answer
time: 1ms
memory: 4368kb

input:

1
0 -1000 0

output:

0

result:

wrong answer 1st lines differ - expected: '1000000', found: '0'