QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#68932 | #5111. Take On Meme | chenshi | WA | 121ms | 23016kb | C++14 | 2.6kb | 2022-12-21 23:30:43 | 2022-12-21 23:30:44 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const long long o=10010;
struct Point{
long long x,y;
Point(long long _x=0,long long _y=0):x(_x),y(_y){}
Point operator+(Point b)const{return Point(x+b.x,y+b.y);}
Point operator-(Point b)const{return Point(x-b.x,y-b.y);}
long long operator*(Point b)const{return x*b.x+y*b.y;}
long long operator^(Point b)const{return x*b.y-y*b.x;}
Point operator*(long long b)const{return Point(x*b,y*b);}
long long normsqr(){return x*x+y*y;}
};
Point p1;
inline bool cmp(Point p2,Point p3){
long long t=(p1-p3)^(p2-p3);
return t>0||(!t&&((p1-p2)*(p1-p2))<((p1-p3)*(p1-p3)));
}
vector<Point> graham(vector<Point> p){
if(p.empty()) return p;
vector<Point> res;
p1=p[0];
for(int i=p.size();i--;) if(p[i].y<p1.y||(p[i].y==p1.y&&p[i].x<p1.x)) p1=p[i];
sort(p.begin(),p.end(),cmp);
for(int i=0,sz=p.size();i<sz;res.push_back(p[i++]))
for(;(int)res.size()>1&&((res.back()-res[res.size()-2])^(p[i]-res[res.size()-2]))<=0;res.pop_back());
return res;
}
inline void point_to_edge(vector<Point>&res,long long&x,long long &y,vector<Point> vec){
x+=vec[0].x;y+=vec[0].y;
for(int i=1,sz=vec.size();i<sz;++i) res.push_back(vec[i]-vec[i-1]);
if((int)vec.size()>1) res.push_back(vec[0]-vec.back());
}
inline bool Cmp(Point A,Point B){
bool x=(A.y>0||(A.y==0&&A.x>0)),y=(B.y>0||(B.y==0&&B.x>0));
if(x^y) return x;
return (A^B)>0;
}
inline void edge_to_point(vector<Point>&res,long long x,long long y,vector<Point> vec){
if(vec.empty()) res.push_back(Point(x,y));
sort(vec.begin(),vec.end(),Cmp);
for(int i=0,sz=vec.size();i<sz;++i) res.push_back(Point(x,y)),x+=vec[i].x,y+=vec[i].y;
}
int n;long long ans,dx[o],dy[o];vector<int> sn[o];vector<Point> conv[o];
void dfs(int nw){
if(sn[nw].empty()) return;
for(int i=sn[nw].size();i--;) dfs(sn[nw][i]);
long long Dx,Dy;vector<Point> vec,t;
for(int i=sn[nw].size();i--;edge_to_point(conv[nw],Dx,Dy,vec)){
Dx=dx[sn[nw][i]];Dy=dy[sn[nw][i]];vec=conv[sn[nw][i]];
for(int j=sn[nw].size();j--;) if(i^j){
t.clear();edge_to_point(t,dx[sn[nw][j]],dy[sn[nw][j]],conv[sn[nw][j]]);
for(int k=t.size();k--;) t[k].x*=-1,t[k].y*=-1;
point_to_edge(vec,Dx,Dy,graham(t));
}
}
if(nw==1) for(int i=conv[nw].size();i--;) ans=max(ans,conv[nw][i].normsqr());
else vec=conv[nw],conv[nw].clear(),point_to_edge(conv[nw],dx[nw],dy[nw],graham(vec));
}
int main(){
scanf("%d",&n);
for(int i=1,k,t;i<=n;++i){
scanf("%d",&k);
if(!k) scanf("%lld%lld",&dx[i],&dy[i]);
for(;k--;sn[i].push_back(t)) scanf("%d",&t);
}
dfs(1);
printf("%lld",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3460kb
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: 3ms
memory: 3500kb
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: 2ms
memory: 3700kb
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: 97ms
memory: 15876kb
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: 119ms
memory: 15328kb
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: 121ms
memory: 23016kb
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: 3ms
memory: 3452kb
input:
1 0 0 0
output:
0
result:
ok single line: '0'
Test #8:
score: -100
Wrong Answer
time: 3ms
memory: 3472kb
input:
1 0 -1000 0
output:
0
result:
wrong answer 1st lines differ - expected: '1000000', found: '0'