QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#95491 | #5111. Take On Meme | marcosk | WA | 2ms | 4028kb | C++14 | 3.3kb | 2023-04-10 00:24:43 | 2023-04-10 00:24: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;
}
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)==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;
}
// 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);
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";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4028kb
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: 3932kb
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: 0ms
memory: 3932kb
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:
5040321437479736281
result:
wrong answer 1st lines differ - expected: '26269', found: '5040321437479736281'