QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#387044 | #5111. Take On Meme | Energy_is_not_over | WA | 409ms | 10404kb | C++17 | 6.1kb | 2024-04-11 23:55:45 | 2024-04-11 23:55:45 |
Judging History
answer
//
// Stvoreno ENERGom o 11.04.24. 16:40:54
//
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define F first
#define fir first
#define S second
#define sec second
#define mp make_pair
#define MP make_pair
#define pb push_back
#define PB push_back
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
#ifdef Energy
#define DEBUG for (int _____DEBUG=1;_____DEBUG;_____DEBUG=0)
template<class ...Ts>
auto &PRNT(Ts ...ts) { return ((cerr << ts << " "), ...); }
#define LOG(...) PRNT(#__VA_ARGS__" ::",__VA_ARGS__)<<endl
#else
#define DEBUG while (0)
#define LOG(...)
#endif
const int max_n = 10011, inf = 1000111222;
const ld pi = 2 * acosl(0.0l);
const int max_its = 50;
struct Point {
int x, y;
Point operator - (const Point &p) const {
return {x - p.x, y - p.y};
}
};
int n;
vector<int> g[max_n];
Point p[max_n];
vector<Point> points;
vector<ld> angs;
void add(ld ang) {
if (ang >= 2 * pi) {
ang -= 2 * pi;
}
angs.push_back(ang);
}
const ld phi = (sqrtl(5) - 1) / 2;
const ld phi1 = 1 - phi;
const int max_cands = 4 * max_n;
ld val[max_n];
pair<ld, pair<int, int>> dp[max_n][2], tmp[2][2];
void upd(pair<ld, pair<int, int>> &a, const pair<ld, pair<int, int>> &b) {
a = max(a, b);
}
pair<ld, pair<int, int>> comb(const pair<ld, pair<int, int>> &a, const pair<ld, pair<int, int>> &b) {
return {a.first + b.first, {a.second.first + b.second.first, a.second.second + b.second.second}};
}
int q1 = 0, q2 = 1;
void calc(int v) {
for (int to : g[v]) {
calc(to);
}
for (int f = 0; f < 2; ++f) {
int sign = 1 - 2 * f;
if (g[v].empty()) {
dp[v][f] = {sign * val[v], {p[v].x * sign, p[v].y * sign}};
continue;
}
tmp[q1][0] = {-1e18, {0, 0}};
tmp[q1][1] = {-1e18, {0, 0}};
tmp[q1][0] = {0, {0, 0}};
for (int to : g[v]) {
tmp[q2][0] = {-1e18, {0, 0}};
tmp[q2][1] = {-1e18, {0, 0}};
for (int cur = 0; cur < 2; ++cur) {
for (int take = 0; cur + take < 2; ++take) {
upd(tmp[q2][cur + take], comb(tmp[q1][cur], dp[to][f ^ take]));
}
}
swap(q1, q2);
}
dp[v][f] = tmp[q1][1];
}
// LOG(v, dp[v][0].first, dp[v][1].first);
}
pair<ld, ll> f(ld ang) {
ld dx = cosl(ang), dy = sinl(ang);
const ld A = -dy, B = dx, C = 0;
const ld SQ = sqrtl(A * A + B * B);
for (int i = 0; i < n; ++i) {
if (g[i].empty()) {
ld dd = (A * p[i].x + B * p[i].y + C) / SQ;
ld dot = (dx * p[i].x + dy * p[i].y);
val[i] = sqrtl(p[i].x * p[i].x + p[i].y * p[i].y - dd * dd);
if (dot < 0) {
val[i] *= -1;
}
// LOG(i, dd, val[i]);
}
}
// LOG(val[3] + val[2] + val[1]);
calc(0);
return {dp[0][0].first, 1LL * dp[0][0].second.first * dp[0][0].second.first + 1LL * dp[0][0].second.second * dp[0][0].second.second};
}
struct Data {
ld L, R, m1, m2;
pair<ld, ll> ans1, ans2;
pair<ld, ll> get_ans() {
return max(ans1, ans2);
}
void init(ld LL, ld RR) {
L = LL;
R = RR;
m1 = L * phi + R * phi1;
ans1 = f(m1);
m2 = L * phi1 + R * phi;
ans2 = f(m2);
}
void iter() {
if (ans1 > ans2) {
R = m2;
m2 = m1;
ans2 = ans1;
m1 = L * phi + R * phi1;
ans1 = f(m1);
} else {
L = m1;
m1 = m2;
ans1 = ans2;
m2 = L * phi1 + R * phi;
ans2 = f(m2);
}
}
ll get_ok_ans() {
return max(ans1.second, ans2.second);
}
};
Data d[max_cands];
void dfs(int v, int h = 0) {
for (int to : g[v]) {
dfs(to, h ^ 1);
}
if (g[v].empty()) {
if (h) {
p[v].x *= -1;
p[v].y *= -1;
}
}
}
int main() {
// freopen("input_k.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
if (!k) {
cin >> p[i].x >> p[i].y;
LOG(p[i].x, p[i].y);
} else {
while (k--) {
int to;
cin >> to;
--to;
g[i].push_back(to);
}
}
}
dfs(0);
for (int i = 0; i < n; ++i) {
if (p[i].x || p[i].y) {
points.push_back(p[i]);
}
}
if (0) {
auto [d1, d2] = f(atan2(-12, 5));
LOG(d1, d2);
LOG(d1 * d1);
return 0;
}
angs.push_back(0);
angs.push_back(2 * pi);
for (int it = 1; it < 8; ++it) {
angs.push_back(it * 2 * pi / 8);
}
// for (auto p : points) {
// ld ang = atan2l(p.y, p.x);
// if (ang < 0) {
// ang += 2 * pi;
// }
// add(ang + pi / 2);
// add(ang + 3 * pi / 2);
// }
sort(angs.begin(), angs.end());
vector<pair<pair<ld, ll>, int>> cands, ncands;
for (int i = 0; i + 1 < angs.size(); ++i) {
d[i].init(angs[i], angs[i + 1]);
cands.push_back({{0, 0}, i});
}
ll ans = 0;
for (int it = 0; it < max_its; ++it) {
ncands.clear();
for (auto [P, id] : cands) {
d[id].iter();
ans = max(ans, d[id].get_ok_ans());
ncands.push_back({d[id].get_ans(), id});
}
int to_leave = ncands.size();
// to_leave = 10;
if (it > 3) {
// to_leave *= 0.74;
// to_leave = max(to_leave, 47);
}
nth_element(ncands.begin(), ncands.begin() + to_leave, ncands.end(), greater<pair<pair<ld, ll>, int>>());
if (ncands.size() > to_leave) {
ncands.resize(to_leave);
}
cands.swap(ncands);
}
cout << ans << "\n";
exit(0);
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9168kb
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: 9044kb
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: 3ms
memory: 9044kb
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: 360ms
memory: 10392kb
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: 359ms
memory: 10384kb
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: 356ms
memory: 10404kb
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: 9148kb
input:
1 0 0 0
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 3ms
memory: 9332kb
input:
1 0 -1000 0
output:
1000000
result:
ok single line: '1000000'
Test #9:
score: 0
Accepted
time: 0ms
memory: 9176kb
input:
1 0 0 -1000
output:
1000000
result:
ok single line: '1000000'
Test #10:
score: 0
Accepted
time: 0ms
memory: 9132kb
input:
1 0 -1000 1000
output:
2000000
result:
ok single line: '2000000'
Test #11:
score: 0
Accepted
time: 0ms
memory: 9216kb
input:
2 1 2 0 0 0
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 3ms
memory: 9144kb
input:
2 1 2 0 -123 -456
output:
223065
result:
ok single line: '223065'
Test #13:
score: 0
Accepted
time: 0ms
memory: 9224kb
input:
3 2 2 3 0 123 456 0 123 456
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 3ms
memory: 9372kb
input:
3 2 2 3 0 -123 456 0 123 456
output:
60516
result:
ok single line: '60516'
Test #15:
score: 0
Accepted
time: 0ms
memory: 9152kb
input:
3 2 2 3 0 123 456 0 123 -456
output:
831744
result:
ok single line: '831744'
Test #16:
score: 0
Accepted
time: 0ms
memory: 9316kb
input:
3 2 2 3 0 -123 456 0 123 -456
output:
892260
result:
ok single line: '892260'
Test #17:
score: 0
Accepted
time: 3ms
memory: 9076kb
input:
3 2 2 3 0 -123 456 0 345 678
output:
268308
result:
ok single line: '268308'
Test #18:
score: 0
Accepted
time: 3ms
memory: 9360kb
input:
3 1 2 1 3 0 -123 -456
output:
223065
result:
ok single line: '223065'
Test #19:
score: 0
Accepted
time: 0ms
memory: 9296kb
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: 3ms
memory: 9168kb
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: 0ms
memory: 9364kb
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: 0ms
memory: 9144kb
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: 3ms
memory: 9132kb
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: 3ms
memory: 9364kb
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: 3ms
memory: 9316kb
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: 3ms
memory: 9156kb
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: 39ms
memory: 9324kb
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: 0
Accepted
time: 259ms
memory: 9856kb
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:
3021509835725
result:
ok single line: '3021509835725'
Test #29:
score: 0
Accepted
time: 320ms
memory: 10228kb
input:
9331 6 2 1557 3112 4667 6222 7777 6 3 262 521 780 1039 1298 6 4 47 90 133 176 219 6 5 12 19 26 33 40 6 6 7 8 9 10 11 0 -236 -302 0 39 410 0 -424 -529 0 107 319 0 -705 -271 0 9 52 6 13 14 15 16 17 18 0 -385 -363 0 -271 -170 0 611 507 0 283 -357 0 582 -994 0 687 -118 6 20 21 22 23 24 25 0 -338 394 0 -...
output:
7634291710385
result:
ok single line: '7634291710385'
Test #30:
score: 0
Accepted
time: 320ms
memory: 10200kb
input:
9901 99 2 102 202 302 402 502 602 702 802 902 1002 1102 1202 1302 1402 1502 1602 1702 1802 1902 2002 2102 2202 2302 2402 2502 2602 2702 2802 2902 3002 3102 3202 3302 3402 3502 3602 3702 3802 3902 4002 4102 4202 4302 4402 4502 4602 4702 4802 4902 5002 5102 5202 5302 5402 5502 5602 5702 5802 5902 6002...
output:
118831327360
result:
ok single line: '118831327360'
Test #31:
score: -100
Wrong Answer
time: 409ms
memory: 10336kb
input:
9901 99 2 102 202 302 402 502 602 702 802 902 1002 1102 1202 1302 1402 1502 1602 1702 1802 1902 2002 2102 2202 2302 2402 2502 2602 2702 2802 2902 3002 3102 3202 3302 3402 3502 3602 3702 3802 3902 4002 4102 4202 4302 4402 4502 4602 4702 4802 4902 5002 5102 5202 5302 5402 5502 5602 5702 5802 5902 6002...
output:
42043025
result:
wrong answer 1st lines differ - expected: '15242981', found: '42043025'