QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#95488 | #5111. Take On Meme | marcosk | WA | 2ms | 3968kb | C++14 | 2.7kb | 2023-04-10 00:03:44 | 2023-04-10 00:03:47 |
Judging History
answer
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
struct pt{
ll x,y;
pt(){}
pt(ll x, ll y):x(x),y(y){}
ll norm2(){return *this**this;}
pt operator +(pt p){return pt(x+p.x,y+p.y);}
pt operator -(pt p){return pt(x-p.x,y-p.y);}
pt operator *(ll k){return pt(x*k,y*k);}
pt operator /(ll k){return pt(x/k,y/k);}
ll operator *(pt p){return x*p.x+y*p.y;}
ll operator %(pt p){return x*p.y-y*p.x;}
bool left(pt p, pt q){return (q-p)%(*this-p)>=0;}
bool operator <(pt p){return x<p.x||(x==p.x&&y<p.y);}
};
typedef vector<pt> poly;
vector<pt> chull(vector<pt> p){
if(SZ(p)<3)return p;
vector<pt> r;
sort(ALL(p));
fore(i,0,p.size()){
while(r.size()>=2&&r.back().left(r[r.size()-2],p[i]))r.pop_back();
r.pb(p[i]);
}
r.pop_back();
int k=r.size();
for(int i=p.size()-1;i>=0;--i){
while(r.size()>=k+2&&r.back().left(r[r.size()-2],p[i]))r.pop_back();
r.pb(p[i]);
}
r.pop_back();
return r;
}
poly add(poly p, poly q){
if(!SZ(p)) return q;
if(!SZ(q)) return p;
if(SZ(p)==1){
for(auto &x:q) x=(x+p[0]);
return q;
}
if(SZ(q)==1){
for(auto &x:p) x=(x+q[0]);
return p;
}
int n=SZ(p),m=SZ(q),x=0,y=0;
fore(i,0,n) if(p[i]<p[x]) x=i;
fore(i,0,m) if(q[i]<q[y]) y=i;
poly ans={p[x]+q[y]};
fore(it,1,n+m){
pt a=p[(x+1)%n]+q[y];
pt b=p[x]+q[(y+1)%m];
if(b.left(ans.back(),a)) ans.pb(b), y=(y+1)%m;
else ans.pb(a), x=(x+1)%n;
}
return chull(ans);
}
poly mul(poly p, ll k){
for(auto &x:p) x=x*k;
return p;
}
const int MAXN=10010;
poly wh[MAXN];
vector<int> g[MAXN];
void dfs(int pos){
if(!SZ(g[pos])) return;
for(auto x:g[pos]) dfs(x);
vector<poly> lef,rig;
poly now;
fore(i,0,SZ(g[pos])){
lef.pb(now);
reverse(ALL(wh[g[pos][i]]));
now=add(now,mul(wh[g[pos][i]],-1));
reverse(ALL(wh[g[pos][i]]));
}
now.clear();
for(int i=SZ(g[pos])-1;i>=0;i--){
rig.pb(now);
reverse(ALL(wh[g[pos][i]]));
now=add(now,mul(wh[g[pos][i]],-1));
reverse(ALL(wh[g[pos][i]]));
}
reverse(ALL(rig));
poly all;
fore(i,0,SZ(g[pos])){
now=add(wh[g[pos][i]], add(lef[i],rig[i]));
for(auto p:now) all.pb(p);
}
wh[pos]=chull(all);
}
int main(){FIN;
int n; cin>>n;
fore(i,0,n){
int k; cin>>k;
if(k==0){
int x,y; cin>>x>>y;
wh[i].pb(pt(x,y));
}
else{
fore(j,0,k){
int x; cin>>x; x--;
g[i].pb(x);
}
}
}
dfs(0);
ll ans=0;
for(auto p:wh[0]) ans=max(ans, p.norm2());
cout<<ans<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3928kb
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: 2ms
memory: 3924kb
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: -100
Wrong Answer
time: 2ms
memory: 3968kb
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:
16981
result:
wrong answer 1st lines differ - expected: '26269', found: '16981'