QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#189257 | #5111. Take On Meme | bulijiojiodibuliduo# | WA | 20ms | 6056kb | C++17 | 4.4kb | 2023-09-27 05:35:06 | 2023-09-27 05:35:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
//typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
typedef long long db;
const db EPS = 0;
inline int sign(db a) { return a < -EPS ? -1 : a > EPS; }
inline int cmp(db a, db b){ return sign(a-b); }
struct P {
db x, y;
P() {}
P(db _x, db _y) : x(_x), y(_y) {}
P operator+(P p) { return {x + p.x, y + p.y}; }
P operator-(P p) { return {x - p.x, y - p.y}; }
P operator*(db d) { return {x * d, y * d}; }
P operator/(db d) { return {x / d, y / d}; }
bool operator<(P p) const {
int c = cmp(x, p.x);
if (c) return c == -1;
return cmp(y, p.y) == -1;
}
bool operator==(P o) const{
return cmp(x,o.x) == 0 && cmp(y,o.y) == 0;
}
db dot(P p) { return x * p.x + y * p.y; }
db det(P p) { return x * p.y - y * p.x; }
db abs2() { return x * x + y * y; }
P rot90() { return P(-y,x);}
int quad() const { return sign(y) == 1 || (sign(y) == 0 && sign(x) >= 0); }
};
#define cross(p1,p2,p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))
#define crossOp(p1,p2,p3) sign(cross(p1,p2,p3))
vector<P> convexHull(vector<P> ps) {
int n = ps.size(); if(n <= 1) return ps;
sort(ps.begin(), ps.end());
vector<P> qs(n * 2); int k = 0;
for (int i = 0; i < n; qs[k++] = ps[i++])
while (k > 1 && crossOp(qs[k - 2], qs[k - 1], ps[i]) <= 0) --k;
for (int i = n - 2, t = k; i >= 0; qs[k++] = ps[i--])
while (k > t && crossOp(qs[k - 2], qs[k - 1], ps[i]) <= 0) --k;
qs.resize(k - 1);
return qs;
}
vector<P> merge(vector<P> a,vector<P> b) {
rotate(a.begin(),min_element(a.begin(), a.end()),a.end());
rotate(b.begin(),min_element(b.begin(), b.end()),b.end());
//assert(b==convexHull(b));
vector<P> c;
int p1=0,p2=0;
while (p1<SZ(a)||p2<SZ(b)) {
c.pb(a[p1%SZ(a)]+b[p2%SZ(b)]);
P d1=a[(p1+1)%SZ(a)]-a[p1],d2=b[(p2+1)%SZ(b)]-b[p2];
auto dcmp=[&](P d1,P d2) {
int q1=d1==P(0,0)?2:((sign(d1.x)>0||(sign(d1.x)==0&&sign(d1.y)<0))?0:1);
int q2=d2==P(0,0)?2:((sign(d2.x)>0||(sign(d2.x)==0&&sign(d2.y)<0))?0:1);
if (q1!=q2) return cmp(q1,q2);
else return -sign(d1.det(d2));
};
if (p1<SZ(a)&&p2<SZ(b)&&dcmp(d1,d2)==0) {
p1++;
p2++;
} else if (p2==SZ(b)||(p1<SZ(a)&&dcmp(d1,d2)==-1)) {
p1++;
} else {
p2++;
}
}
/*
vector<P> d;
for (auto x:a) for (auto y:b) d.pb(x+y);
d=convexHull(d);
puts("merge");
for (auto p:a) printf("(%lld,%lld) ",p.x,p.y); puts("");
for (auto p:b) printf("(%lld,%lld) ",p.x,p.y); puts("");
for (auto p:c) printf("(%lld,%lld) ",p.x,p.y); puts("");
for (auto p:d) printf("(%lld,%lld) ",p.x,p.y); puts("");*/
return c;
}
const int N=10100;
vector<P> ch[N];
VI son[N];
int n;
vector<P> neg(vector<P> ps) {
for (auto &p:ps) p=p*(-1);
return ps;
}
void gao(int u) {
if (son[u].empty()) {
return;
}
for (auto v:son[u]) gao(v);
function<pair<vector<P>,vector<P>>(int,int)> solve=[&](int l,int r) {
if (l==r) {
int v=son[u][l];
auto p1=ch[v],p2=neg(ch[v]);
return mp(p1,p2);
} else {
int md=(l+r)>>1;
auto [p1,p2]=solve(l,md);
auto [q1,q2]=solve(md+1,r);
auto r2=merge(p2,q2);
auto r11=merge(p1,q2);
auto r12=merge(p2,q1);
r11.insert(r11.end(),all(r12));
auto r1=convexHull(r11);
/*printf("Solve %d %d %d\n",u,l,r);
for (auto p:r1) printf("(%lld,%lld) ",p.x,p.y); puts("");
for (auto p:r2) printf("(%lld,%lld) ",p.x,p.y); puts("");*/
return mp(r1,r2);
}
};
auto [r1,r2]=solve(0,SZ(son[u])-1);
ch[u]=r1;
}
int main() {
scanf("%d",&n);
rep(i,1,n+1) {
int k;
scanf("%d",&k);
if (k>0) {
rep(j,0,k) {
int x;
scanf("%d",&x);
son[i].pb(x);
}
} else {
int x,y;
scanf("%d%d",&x,&y);
ch[i].pb(P(x,y));
}
}
gao(1);
db ans=0;
for (auto [x,y]:ch[1]) ans=max(ans,x*x+y*y);
printf("%lld\n",ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4192kb
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: 4188kb
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: 4180kb
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: 20ms
memory: 5876kb
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: 20ms
memory: 5928kb
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: 20ms
memory: 6056kb
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: 4180kb
input:
1 0 0 0
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 1ms
memory: 4176kb
input:
1 0 -1000 0
output:
1000000
result:
ok single line: '1000000'
Test #9:
score: 0
Accepted
time: 1ms
memory: 4172kb
input:
1 0 0 -1000
output:
1000000
result:
ok single line: '1000000'
Test #10:
score: 0
Accepted
time: 0ms
memory: 4292kb
input:
1 0 -1000 1000
output:
2000000
result:
ok single line: '2000000'
Test #11:
score: 0
Accepted
time: 1ms
memory: 4276kb
input:
2 1 2 0 0 0
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 1ms
memory: 4204kb
input:
2 1 2 0 -123 -456
output:
223065
result:
ok single line: '223065'
Test #13:
score: 0
Accepted
time: 1ms
memory: 4216kb
input:
3 2 2 3 0 123 456 0 123 456
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 1ms
memory: 4180kb
input:
3 2 2 3 0 -123 456 0 123 456
output:
60516
result:
ok single line: '60516'
Test #15:
score: 0
Accepted
time: 1ms
memory: 4252kb
input:
3 2 2 3 0 123 456 0 123 -456
output:
831744
result:
ok single line: '831744'
Test #16:
score: 0
Accepted
time: 1ms
memory: 4180kb
input:
3 2 2 3 0 -123 456 0 123 -456
output:
892260
result:
ok single line: '892260'
Test #17:
score: 0
Accepted
time: 0ms
memory: 4200kb
input:
3 2 2 3 0 -123 456 0 345 678
output:
268308
result:
ok single line: '268308'
Test #18:
score: 0
Accepted
time: 1ms
memory: 4248kb
input:
3 1 2 1 3 0 -123 -456
output:
223065
result:
ok single line: '223065'
Test #19:
score: 0
Accepted
time: 1ms
memory: 4212kb
input:
4 3 2 3 4 0 1 0 0 1 0 0 1 0
output:
1
result:
ok single line: '1'
Test #20:
score: 0
Accepted
time: 0ms
memory: 4208kb
input:
6 2 2 3 3 4 5 6 0 1 0 0 1 0 0 1 0 0 1 0
output:
4
result:
ok single line: '4'
Test #21:
score: 0
Accepted
time: 1ms
memory: 4192kb
input:
6 2 2 3 3 4 5 6 0 -1 0 0 1 0 0 1 0 0 1 0
output:
0
result:
ok single line: '0'
Test #22:
score: 0
Accepted
time: 1ms
memory: 4172kb
input:
9 2 2 3 3 4 5 6 3 7 8 9 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0
output:
0
result:
ok single line: '0'
Test #23:
score: 0
Accepted
time: 1ms
memory: 4176kb
input:
11 2 2 3 3 5 6 7 2 4 8 3 9 10 11 0 1 0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 0
output:
4
result:
ok single line: '4'
Test #24:
score: 0
Accepted
time: 1ms
memory: 4208kb
input:
7 2 2 3 4 4 5 6 7 0 -1 1 0 1 0 0 0 1 0 -1 0 0 0 -1
output:
10
result:
ok single line: '10'
Test #25:
score: 0
Accepted
time: 1ms
memory: 4204kb
input:
11 10 2 3 4 5 6 7 8 9 10 11 0 102 -967 0 986 -21 0 709 -570 0 -987 -692 0 571 -682 0 -926 -89 0 -872 600 0 137 -79 0 -844 100 0 -171 359
output:
14669290
result:
ok single line: '14669290'
Test #26:
score: 0
Accepted
time: 1ms
memory: 4224kb
input:
111 10 2 13 24 35 46 57 68 79 90 101 10 3 4 5 6 7 8 9 10 11 12 0 802 -636 0 314 100 0 854 515 0 564 -305 0 905 -624 0 -145 -402 0 -342 828 0 -589 776 0 -51 163 0 929 58 10 14 15 16 17 18 19 20 21 22 23 0 321 177 0 497 -114 0 905 -669 0 987 301 0 754 -48 0 594 861 0 -76 -2 0 -450 -850 0 -428 286 0 83...
output:
943392365
result:
ok single line: '943392365'
Test #27:
score: 0
Accepted
time: 2ms
memory: 4444kb
input:
1111 10 2 113 224 335 446 557 668 779 890 1001 10 3 14 25 36 47 58 69 80 91 102 10 4 5 6 7 8 9 10 11 12 13 0 -846 43 0 794 332 0 -558 -43 0 -642 -438 0 -245 936 0 -289 489 0 -643 211 0 876 -116 0 -743 290 0 -411 587 10 15 16 17 18 19 20 21 22 23 24 0 -458 -210 0 -967 244 0 -220 -827 0 632 -261 0 970...
output:
66275717341
result:
ok single line: '66275717341'
Test #28:
score: -100
Wrong Answer
time: 13ms
memory: 5328kb
input:
7381 9 2 822 1642 2462 3282 4102 4922 5742 6562 9 3 94 185 276 367 458 549 640 731 9 4 14 24 34 44 54 64 74 84 9 5 6 7 8 9 10 11 12 13 0 -644 -151 0 -950 349 0 344 145 0 161 -819 0 571 303 0 481 531 0 -644 105 0 821 802 0 -697 909 9 15 16 17 18 19 20 21 22 23 0 -421 -543 0 -816 889 0 773 -254 0 -219...
output:
3012595496753
result:
wrong answer 1st lines differ - expected: '3021509835725', found: '3012595496753'