QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#95493 | #5111. Take On Meme | marcosk | RE | 2ms | 3992kb | C++14 | 3.1kb | 2023-04-10 00:41:06 | 2023-04-10 00:41:09 |
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;
}
void reorder_polygon(vector<pt> & P){
size_t pos = 0;
for(size_t i = 1; i < P.size(); i++){
if(P[i].y < P[pos].y || (P[i].y == P[pos].y && P[i].x < P[pos].x))
pos = i;
}
rotate(P.begin(), P.begin() + pos, P.end());
}
vector<pt> add(vector<pt> P, vector<pt> Q){
if(!SZ(P)) return Q;
if(!SZ(Q)) return P;
if(SZ(P)<3|| SZ(Q)<3){
vector<pt> v;
for(auto pp:P) for(auto qq:Q) v.pb(pp+qq);
return chull(v);
}
// the first vertex must be the lowest
reorder_polygon(P);
reorder_polygon(Q);
// we must ensure cyclic indexing
P.push_back(P[0]);
P.push_back(P[1]);
Q.push_back(Q[0]);
Q.push_back(Q[1]);
// main part
vector<pt> result;
size_t i = 0, j = 0;
while(i < P.size() - 2 || j < Q.size() - 2){
result.push_back(P[i] + Q[j]);
auto cross = (P[i + 1] - P[i])%(Q[j + 1] - Q[j]);
if(cross >= 0)
++i;
if(cross <= 0)
++j;
}
return result;
}
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);
now=add(now,mul(wh[g[pos][i]],-1));
}
now.clear();
for(int i=SZ(g[pos])-1;i>=0;i--){
rig.pb(now);
now=add(now,mul(wh[g[pos][i]],-1));
}
reverse(ALL(rig));
poly all;
fore(i,0,SZ(g[pos])){
reverse(ALL(wh[g[pos][i]]));
now=add(wh[g[pos][i]], add(lef[i],rig[i]));
reverse(ALL(wh[g[pos][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: 3976kb
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: 3992kb
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: -100
Runtime Error
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 ...