mirror of
https://github.com/javalsai/aoc.git
synced 2026-01-13 01:19:59 +01:00
perf: d09p2 peak perf
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
//!
|
//!
|
||||||
//! I think even adyacent is within the "other rectangle thing", because
|
//! I think even adyacent is within the "other rectangle thing", because
|
||||||
|
|
||||||
use std::ops::Range;
|
use std::{collections::BinaryHeap, ops::Range};
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "Rust" fn challenge_usize(buf: &[u8]) -> usize {
|
pub extern "Rust" fn challenge_usize(buf: &[u8]) -> usize {
|
||||||
@@ -14,27 +14,29 @@ pub extern "Rust" fn challenge_usize(buf: &[u8]) -> usize {
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
// assuming each coord is contiguous to the prev one
|
// assuming each coord is contiguous to the prev one
|
||||||
let mut edges = coords
|
let edges = coords
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.chain([coords[0]])
|
.chain([coords[0]])
|
||||||
.map_windows(|&[a, b]| (a, b))
|
.map_windows(|&[a, b]| (a.0.abs_diff(b.0) + a.1.abs_diff(b.1), (a, b)))
|
||||||
.collect::<Vec<_>>();
|
.collect::<BinaryHeap<_>>();
|
||||||
|
|
||||||
edges.sort_by(|(a1, a2), (b1, b2)| {
|
// edges.sort_by(|(a1, a2), (b1, b2)| {
|
||||||
(a1.0.abs_diff(a2.0) + a1.1.abs_diff(a2.1))
|
// (a1.0.abs_diff(a2.0) + a1.1.abs_diff(a2.1))
|
||||||
.cmp(&(b1.0.abs_diff(b2.0) + b1.1.abs_diff(b2.1)))
|
// .cmp(&(b1.0.abs_diff(b2.0) + b1.1.abs_diff(b2.1)))
|
||||||
});
|
// });
|
||||||
|
|
||||||
let mut max_area = 0;
|
let mut max_area = 0;
|
||||||
for (i, coor1) in coords.iter().enumerate() {
|
for (i, coor1) in coords.iter().enumerate() {
|
||||||
for coor2 in coords.iter().skip(i) {
|
for coor2 in coords.iter().skip(i + 1) {
|
||||||
let dx = coor1.0.abs_diff(coor2.0) + 1;
|
let dx = coor1.0.abs_diff(coor2.0) + 1;
|
||||||
let dy = coor1.1.abs_diff(coor2.1) + 1;
|
let dy = coor1.1.abs_diff(coor2.1) + 1;
|
||||||
let area = dx * dy;
|
let area = dx * dy;
|
||||||
|
|
||||||
if is_really_contained((*coor1, *coor2), &edges) {
|
if area > max_area
|
||||||
max_area = max_area.max(area);
|
&& is_really_contained((*coor1, *coor2), edges.iter().map(|&(_, v)| v))
|
||||||
|
{
|
||||||
|
max_area = area;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +48,7 @@ pub extern "Rust" fn challenge_usize(buf: &[u8]) -> usize {
|
|||||||
/// well contained
|
/// well contained
|
||||||
fn is_really_contained(
|
fn is_really_contained(
|
||||||
(rect0, rect1): ((usize, usize), (usize, usize)),
|
(rect0, rect1): ((usize, usize), (usize, usize)),
|
||||||
edges: &[((usize, usize), (usize, usize))],
|
edges: impl Iterator<Item = ((usize, usize), (usize, usize))>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let (rect0, rect1) = (
|
let (rect0, rect1) = (
|
||||||
(rect0.0.min(rect1.0), rect0.1.min(rect1.1)),
|
(rect0.0.min(rect1.0), rect0.1.min(rect1.1)),
|
||||||
@@ -81,10 +83,7 @@ fn mkrange<T: Ord + Copy>(a: T, b: T) -> Range<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn rangeoverlap<T: Ord>(a: &Range<T>, b: &Range<T>) -> bool {
|
fn rangeoverlap<T: Ord>(a: &Range<T>, b: &Range<T>) -> bool {
|
||||||
if a.end <= b.start {
|
if a.end <= b.start || a.start >= b.end {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if a.start >= b.end {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
496
2025/medium.txt
Normal file
496
2025/medium.txt
Normal file
@@ -0,0 +1,496 @@
|
|||||||
|
97924,50397
|
||||||
|
97924,51628
|
||||||
|
98415,51628
|
||||||
|
98415,52850
|
||||||
|
98292,52850
|
||||||
|
98292,54078
|
||||||
|
98276,54078
|
||||||
|
98276,55288
|
||||||
|
98043,55288
|
||||||
|
98043,56423
|
||||||
|
97303,56423
|
||||||
|
97303,57711
|
||||||
|
97692,57711
|
||||||
|
97692,58821
|
||||||
|
96973,58821
|
||||||
|
96973,60116
|
||||||
|
97239,60116
|
||||||
|
97239,61228
|
||||||
|
96629,61228
|
||||||
|
96629,62473
|
||||||
|
96581,62473
|
||||||
|
96581,63611
|
||||||
|
96121,63611
|
||||||
|
96121,64861
|
||||||
|
96028,64861
|
||||||
|
96028,65764
|
||||||
|
94900,65764
|
||||||
|
94900,67161
|
||||||
|
95183,67161
|
||||||
|
95183,68139
|
||||||
|
94341,68139
|
||||||
|
94341,69483
|
||||||
|
94384,69483
|
||||||
|
94384,70602
|
||||||
|
93878,70602
|
||||||
|
93878,71361
|
||||||
|
92651,71361
|
||||||
|
92651,72634
|
||||||
|
92470,72634
|
||||||
|
92470,73502
|
||||||
|
91529,73502
|
||||||
|
91529,74935
|
||||||
|
91566,74935
|
||||||
|
91566,75703
|
||||||
|
90486,75703
|
||||||
|
90486,76625
|
||||||
|
89679,76625
|
||||||
|
89679,77482
|
||||||
|
88795,77482
|
||||||
|
88795,78448
|
||||||
|
88075,78448
|
||||||
|
88075,79469
|
||||||
|
87427,79469
|
||||||
|
87427,80940
|
||||||
|
87309,80940
|
||||||
|
87309,81352
|
||||||
|
85915,81352
|
||||||
|
85915,82359
|
||||||
|
85225,82359
|
||||||
|
85225,83372
|
||||||
|
84529,83372
|
||||||
|
84529,84413
|
||||||
|
83848,84413
|
||||||
|
83848,84973
|
||||||
|
82697,84973
|
||||||
|
82697,85857
|
||||||
|
81860,85857
|
||||||
|
81860,86358
|
||||||
|
80693,86358
|
||||||
|
80693,87278
|
||||||
|
79886,87278
|
||||||
|
79886,88018
|
||||||
|
78928,88018
|
||||||
|
78928,89234
|
||||||
|
78313,89234
|
||||||
|
78313,89561
|
||||||
|
77051,89561
|
||||||
|
77051,90688
|
||||||
|
76335,90688
|
||||||
|
76335,91332
|
||||||
|
75289,91332
|
||||||
|
75289,91489
|
||||||
|
73962,91489
|
||||||
|
73962,92160
|
||||||
|
72945,92160
|
||||||
|
72945,92340
|
||||||
|
71672,92340
|
||||||
|
71672,93077
|
||||||
|
70689,93077
|
||||||
|
70689,93624
|
||||||
|
69607,93624
|
||||||
|
69607,94386
|
||||||
|
68613,94386
|
||||||
|
68613,94825
|
||||||
|
67476,94825
|
||||||
|
67476,95271
|
||||||
|
66341,95271
|
||||||
|
66341,95771
|
||||||
|
65222,95771
|
||||||
|
65222,96253
|
||||||
|
64092,96253
|
||||||
|
64092,96442
|
||||||
|
62873,96442
|
||||||
|
62873,96830
|
||||||
|
61712,96830
|
||||||
|
61712,97260
|
||||||
|
60555,97260
|
||||||
|
60555,97242
|
||||||
|
59301,97242
|
||||||
|
59301,97199
|
||||||
|
58056,97199
|
||||||
|
58056,97224
|
||||||
|
56834,97224
|
||||||
|
56834,97907
|
||||||
|
55698,97907
|
||||||
|
55698,97847
|
||||||
|
54465,97847
|
||||||
|
54465,97941
|
||||||
|
53251,97941
|
||||||
|
53251,98315
|
||||||
|
52049,98315
|
||||||
|
52049,97884
|
||||||
|
50816,97884
|
||||||
|
50816,98050
|
||||||
|
49601,98050
|
||||||
|
49601,97738
|
||||||
|
48394,97738
|
||||||
|
48394,97503
|
||||||
|
47196,97503
|
||||||
|
47196,97878
|
||||||
|
45954,97878
|
||||||
|
45954,97660
|
||||||
|
44754,97660
|
||||||
|
44754,97727
|
||||||
|
43519,97727
|
||||||
|
43519,97225
|
||||||
|
42364,97225
|
||||||
|
42364,97121
|
||||||
|
41150,97121
|
||||||
|
41150,97347
|
||||||
|
39860,97347
|
||||||
|
39860,96656
|
||||||
|
38765,96656
|
||||||
|
38765,95899
|
||||||
|
37709,95899
|
||||||
|
37709,96368
|
||||||
|
36315,96368
|
||||||
|
36315,95856
|
||||||
|
35193,95856
|
||||||
|
35193,94957
|
||||||
|
34215,94957
|
||||||
|
34215,94420
|
||||||
|
33128,94420
|
||||||
|
33128,94259
|
||||||
|
31893,94259
|
||||||
|
31893,94403
|
||||||
|
30507,94403
|
||||||
|
30507,93364
|
||||||
|
29638,93364
|
||||||
|
29638,92743
|
||||||
|
28592,92743
|
||||||
|
28592,92645
|
||||||
|
27272,92645
|
||||||
|
27272,91967
|
||||||
|
26249,91967
|
||||||
|
26249,91324
|
||||||
|
25210,91324
|
||||||
|
25210,90253
|
||||||
|
24444,90253
|
||||||
|
24444,90070
|
||||||
|
23112,90070
|
||||||
|
23112,89351
|
||||||
|
22123,89351
|
||||||
|
22123,88789
|
||||||
|
21018,88789
|
||||||
|
21018,87886
|
||||||
|
20168,87886
|
||||||
|
20168,86962
|
||||||
|
19347,86962
|
||||||
|
19347,86043
|
||||||
|
18535,86043
|
||||||
|
18535,85116
|
||||||
|
17740,85116
|
||||||
|
17740,84601
|
||||||
|
16558,84601
|
||||||
|
16558,83509
|
||||||
|
15930,83509
|
||||||
|
15930,82715
|
||||||
|
15007,82715
|
||||||
|
15007,82025
|
||||||
|
13957,82025
|
||||||
|
13957,81151
|
||||||
|
13098,81151
|
||||||
|
13098,79859
|
||||||
|
12754,79859
|
||||||
|
12754,79147
|
||||||
|
11692,79147
|
||||||
|
11692,77947
|
||||||
|
11271,77947
|
||||||
|
11271,77372
|
||||||
|
9969,77372
|
||||||
|
9969,75883
|
||||||
|
10009,75883
|
||||||
|
10009,75017
|
||||||
|
9112,75017
|
||||||
|
9112,74052
|
||||||
|
8356,74052
|
||||||
|
8356,73174
|
||||||
|
7420,73174
|
||||||
|
7420,71902
|
||||||
|
7208,71902
|
||||||
|
7208,70981
|
||||||
|
6313,70981
|
||||||
|
6313,69530
|
||||||
|
6548,69530
|
||||||
|
6548,68561
|
||||||
|
5737,68561
|
||||||
|
5737,67493
|
||||||
|
5130,67493
|
||||||
|
5130,66441
|
||||||
|
4451,66441
|
||||||
|
4451,65197
|
||||||
|
4304,65197
|
||||||
|
4304,64071
|
||||||
|
3813,64071
|
||||||
|
3813,62733
|
||||||
|
4061,62733
|
||||||
|
4061,61563
|
||||||
|
3763,61563
|
||||||
|
3763,60526
|
||||||
|
2868,60526
|
||||||
|
2868,59320
|
||||||
|
2658,59320
|
||||||
|
2658,58003
|
||||||
|
3110,58003
|
||||||
|
3110,56912
|
||||||
|
2236,56912
|
||||||
|
2236,55612
|
||||||
|
2815,55612
|
||||||
|
2815,54463
|
||||||
|
2176,54463
|
||||||
|
2176,53256
|
||||||
|
1991,53256
|
||||||
|
1991,52027
|
||||||
|
2191,52027
|
||||||
|
2191,50822
|
||||||
|
1746,50822
|
||||||
|
1746,50372
|
||||||
|
94926,50372
|
||||||
|
94926,48373
|
||||||
|
1650,48373
|
||||||
|
1650,47151
|
||||||
|
1748,47151
|
||||||
|
1748,45959
|
||||||
|
2182,45959
|
||||||
|
2182,44724
|
||||||
|
2070,44724
|
||||||
|
2070,43482
|
||||||
|
2000,43482
|
||||||
|
2000,42352
|
||||||
|
2701,42352
|
||||||
|
2701,41171
|
||||||
|
2990,41171
|
||||||
|
2990,39906
|
||||||
|
2866,39906
|
||||||
|
2866,38738
|
||||||
|
3231,38738
|
||||||
|
3231,37620
|
||||||
|
3768,37620
|
||||||
|
3768,36462
|
||||||
|
4129,36462
|
||||||
|
4129,35396
|
||||||
|
4769,35396
|
||||||
|
4769,34029
|
||||||
|
4511,34029
|
||||||
|
4511,32910
|
||||||
|
5004,32910
|
||||||
|
5004,31796
|
||||||
|
5503,31796
|
||||||
|
5503,30544
|
||||||
|
5679,30544
|
||||||
|
5679,29790
|
||||||
|
6959,29790
|
||||||
|
6959,28477
|
||||||
|
7028,28477
|
||||||
|
7028,27438
|
||||||
|
7667,27438
|
||||||
|
7667,26258
|
||||||
|
8049,26258
|
||||||
|
8049,25547
|
||||||
|
9236,25547
|
||||||
|
9236,24498
|
||||||
|
9831,24498
|
||||||
|
9831,23395
|
||||||
|
10350,23395
|
||||||
|
10350,22054
|
||||||
|
10551,22054
|
||||||
|
10551,21180
|
||||||
|
11427,21180
|
||||||
|
11427,20298
|
||||||
|
12278,20298
|
||||||
|
12278,19275
|
||||||
|
12950,19275
|
||||||
|
12950,18389
|
||||||
|
13789,18389
|
||||||
|
13789,17359
|
||||||
|
14468,17359
|
||||||
|
14468,16786
|
||||||
|
15633,16786
|
||||||
|
15633,15459
|
||||||
|
16026,15459
|
||||||
|
16026,14915
|
||||||
|
17198,14915
|
||||||
|
17198,14289
|
||||||
|
18270,14289
|
||||||
|
18270,13257
|
||||||
|
18983,13257
|
||||||
|
18983,12899
|
||||||
|
20257,12899
|
||||||
|
20257,11476
|
||||||
|
20687,11476
|
||||||
|
20687,11226
|
||||||
|
22019,11226
|
||||||
|
22019,10137
|
||||||
|
22742,10137
|
||||||
|
22742,9365
|
||||||
|
23699,9365
|
||||||
|
23699,8665
|
||||||
|
24708,8665
|
||||||
|
24708,8556
|
||||||
|
26063,8556
|
||||||
|
26063,7609
|
||||||
|
26928,7609
|
||||||
|
26928,7486
|
||||||
|
28239,7486
|
||||||
|
28239,6654
|
||||||
|
29181,6654
|
||||||
|
29181,6166
|
||||||
|
30298,6166
|
||||||
|
30298,5931
|
||||||
|
31519,5931
|
||||||
|
31519,5378
|
||||||
|
32603,5378
|
||||||
|
32603,5291
|
||||||
|
33861,5291
|
||||||
|
33861,4883
|
||||||
|
34995,4883
|
||||||
|
34995,4410
|
||||||
|
36109,4410
|
||||||
|
36109,3349
|
||||||
|
37068,3349
|
||||||
|
37068,2952
|
||||||
|
38233,2952
|
||||||
|
38233,3324
|
||||||
|
39575,3324
|
||||||
|
39575,2539
|
||||||
|
40655,2539
|
||||||
|
40655,3047
|
||||||
|
41985,3047
|
||||||
|
41985,2019
|
||||||
|
43056,2019
|
||||||
|
43056,2589
|
||||||
|
44360,2589
|
||||||
|
44360,1841
|
||||||
|
45505,1841
|
||||||
|
45505,2455
|
||||||
|
46775,2455
|
||||||
|
46775,1706
|
||||||
|
47951,1706
|
||||||
|
47951,2282
|
||||||
|
49186,2282
|
||||||
|
49186,1769
|
||||||
|
50399,1769
|
||||||
|
50399,2442
|
||||||
|
51599,2442
|
||||||
|
51599,2360
|
||||||
|
52811,2360
|
||||||
|
52811,2429
|
||||||
|
54019,2429
|
||||||
|
54019,1925
|
||||||
|
55291,1925
|
||||||
|
55291,2650
|
||||||
|
56429,2650
|
||||||
|
56429,2307
|
||||||
|
57711,2307
|
||||||
|
57711,2657
|
||||||
|
58890,2657
|
||||||
|
58890,3006
|
||||||
|
60063,3006
|
||||||
|
60063,2863
|
||||||
|
61350,2863
|
||||||
|
61350,3206
|
||||||
|
62530,3206
|
||||||
|
62530,3937
|
||||||
|
63593,3937
|
||||||
|
63593,4278
|
||||||
|
64762,4278
|
||||||
|
64762,4357
|
||||||
|
66024,4357
|
||||||
|
66024,5363
|
||||||
|
66953,5363
|
||||||
|
66953,5729
|
||||||
|
68110,5729
|
||||||
|
68110,6224
|
||||||
|
69216,6224
|
||||||
|
69216,6704
|
||||||
|
70329,6704
|
||||||
|
70329,7396
|
||||||
|
71337,7396
|
||||||
|
71337,8022
|
||||||
|
72371,8022
|
||||||
|
72371,7912
|
||||||
|
73818,7912
|
||||||
|
73818,8887
|
||||||
|
74662,8887
|
||||||
|
74662,9895
|
||||||
|
75460,9895
|
||||||
|
75460,10341
|
||||||
|
76610,10341
|
||||||
|
76610,10916
|
||||||
|
77686,10916
|
||||||
|
77686,11166
|
||||||
|
79014,11166
|
||||||
|
79014,12141
|
||||||
|
79809,12141
|
||||||
|
79809,12986
|
||||||
|
80694,12986
|
||||||
|
80694,13676
|
||||||
|
81709,13676
|
||||||
|
81709,14453
|
||||||
|
82654,14453
|
||||||
|
82654,15685
|
||||||
|
83163,15685
|
||||||
|
83163,16111
|
||||||
|
84454,16111
|
||||||
|
84454,17061
|
||||||
|
85231,17061
|
||||||
|
85231,18137
|
||||||
|
85860,18137
|
||||||
|
85860,19057
|
||||||
|
86653,19057
|
||||||
|
86653,19729
|
||||||
|
87758,19729
|
||||||
|
87758,20935
|
||||||
|
88197,20935
|
||||||
|
88197,22019
|
||||||
|
88774,22019
|
||||||
|
88774,23062
|
||||||
|
89394,23062
|
||||||
|
89394,23670
|
||||||
|
90679,23670
|
||||||
|
90679,25126
|
||||||
|
90652,25126
|
||||||
|
90652,26103
|
||||||
|
91374,26103
|
||||||
|
91374,27203
|
||||||
|
91885,27203
|
||||||
|
91885,27989
|
||||||
|
93001,27989
|
||||||
|
93001,29416
|
||||||
|
92856,29416
|
||||||
|
92856,30167
|
||||||
|
94124,30167
|
||||||
|
94124,31508
|
||||||
|
94095,31508
|
||||||
|
94095,32411
|
||||||
|
95112,32411
|
||||||
|
95112,33829
|
||||||
|
94797,33829
|
||||||
|
94797,34839
|
||||||
|
95584,34839
|
||||||
|
95584,35890
|
||||||
|
96309,35890
|
||||||
|
96309,37146
|
||||||
|
96368,37146
|
||||||
|
96368,38359
|
||||||
|
96544,38359
|
||||||
|
96544,39540
|
||||||
|
96830,39540
|
||||||
|
96830,40764
|
||||||
|
96909,40764
|
||||||
|
96909,41928
|
||||||
|
97289,41928
|
||||||
|
97289,43153
|
||||||
|
97305,43153
|
||||||
|
97305,44320
|
||||||
|
97745,44320
|
||||||
|
97745,45563
|
||||||
|
97541,45563
|
||||||
|
97541,46736
|
||||||
|
98122,46736
|
||||||
|
98122,47964
|
||||||
|
98003,47964
|
||||||
|
98003,49176
|
||||||
|
98319,49176
|
||||||
|
98319,50397
|
||||||
Reference in New Issue
Block a user