File tree Expand file tree Collapse file tree 8 files changed +23
-30
lines changed
s3722_lexicographically_smallest_string_after_reverse
s3723_maximize_sum_of_squares_of_digits
s3724_minimum_operations_to_transform_array
s3725_count_ways_to_choose_coprime_integers_from_rows
s3726_remove_zeros_in_decimal_representation
s3727_maximum_alternating_sum_of_squares
s3728_stable_subarrays_with_equal_boundary_and_interior_sum
s3729_count_distinct_subarrays_divisible_by_k_in_sorted_array Expand file tree Collapse file tree 8 files changed +23
-30
lines changed Original file line number Diff line number Diff line change 11package g3701_3800 .s3722_lexicographically_smallest_string_after_reverse ;
22
3- // #Medium #Biweekly_Contest_168 #2025_10_26_Time_8_ms_ (100.00%)_Space_44.98_MB_(100.00 %)
3+ // #Medium #Biweekly_Contest_168 #2025_10_28_Time_8_ms_ (100.00%)_Space_44.85_MB_(99.91 %)
44
55public class Solution {
66 public String lexSmallest (String s ) {
Original file line number Diff line number Diff line change 11package g3701_3800 .s3723_maximize_sum_of_squares_of_digits ;
22
3- // #Medium #Biweekly_Contest_168 #2025_10_26_Time_8_ms_ (99.81%)_Space_45.78_MB_(_ %)
3+ // #Medium #Biweekly_Contest_168 #2025_10_28_Time_14_ms_ (99.30%)_Space_46.14_MB_(70.05 %)
44
55public class Solution {
66 public String maxSumOfSquares (int places , int sum ) {
Original file line number Diff line number Diff line change 11package g3701_3800 .s3724_minimum_operations_to_transform_array ;
22
3- // #Medium #Biweekly_Contest_168 #2025_10_26_Time_2_ms_ (100.00%)_Space_61 .61_MB_(100.00 %)
3+ // #Medium #Biweekly_Contest_168 #2025_10_28_Time_2_ms_ (100.00%)_Space_62 .61_MB_(5.39 %)
44
55public class Solution {
66 public long minOperations (int [] nums1 , int [] nums2 ) {
Original file line number Diff line number Diff line change 11package g3701_3800 .s3725_count_ways_to_choose_coprime_integers_from_rows ;
22
3- // #Hard #Biweekly_Contest_168 #2025_10_26_Time_31_ms_(92.56%)_Space_49.21_MB_(_ %)
3+ // #Hard #Biweekly_Contest_168 #2025_10_28_Time_30_ms_(93.77%)_Space_47.15_MB_(68.37 %)
44
55import java .util .HashMap ;
66import java .util .Map ;
Original file line number Diff line number Diff line change 11package g3701_3800 .s3726_remove_zeros_in_decimal_representation ;
22
3- // #Easy #Weekly_Contest_473 #2025_10_26_Time_9_ms_(_%)_Space_41.93_MB_(_ %)
3+ // #Easy #Weekly_Contest_473 #2025_10_28_Time_1_ms_(98.76%)_Space_40.81_MB_(93.77 %)
44
55public class Solution {
66 public long removeZeros (long n ) {
Original file line number Diff line number Diff line change 11package g3701_3800 .s3727_maximum_alternating_sum_of_squares ;
22
3- // #Medium #Weekly_Contest_473 #2025_10_26_Time_46_ms_(100.00%)_Space_62.34_MB_(_ %)
3+ // #Medium #Weekly_Contest_473 #2025_10_28_Time_10_ms_(99.97%)_Space_63.08_MB_(17.57 %)
44
55public class Solution {
66 public long maxAlternatingSum (int [] nums ) {
77 int n = nums .length ;
8- long sum = 0 ;
9- int i = 0 ;
10- int j = n - 1 ;
11- for (int k = 0 ; k < n ; k ++) {
12- nums [k ] = nums [k ] * nums [k ];
8+ int need = n / 2 ;
9+ int maxa = 40000 ;
10+ int [] freq = new int [maxa + 1 ];
11+ long total = 0 ;
12+ for (int x : nums ) {
13+ int a = Math .abs (x );
14+ freq [a ]++;
15+ total += 1L * a * a ;
1316 }
14- java .util .Arrays .sort (nums );
15- java .util .List <Long > ans = new java .util .ArrayList <>();
16- while (i < j ) {
17- ans .add ((long ) nums [j ]);
18- ans .add ((long ) nums [i ]);
19- j --;
20- i ++;
21- }
22- if ((n & 1 ) == 1 ) {
23- ans .add ((long ) nums [n / 2 ]);
24- }
25- for (int k = 0 ; k < n ; k ++) {
26- if (k % 2 == 0 ) {
27- sum += ans .get (k );
28- } else {
29- sum -= ans .get (k );
17+ long small = 0 ;
18+ for (int a = 0 ; a <= maxa && need > 0 ; a ++) {
19+ int take = Math .min (freq [a ], need );
20+ if (take > 0 ) {
21+ small += 1L * a * a * take ;
22+ need -= take ;
3023 }
3124 }
32- return sum ;
25+ return total - 2 * small ;
3326 }
3427}
Original file line number Diff line number Diff line change 11package g3701_3800 .s3728_stable_subarrays_with_equal_boundary_and_interior_sum ;
22
3- // #Medium #Weekly_Contest_473 #2025_10_26_Time_124_ms_(100.00 %)_Space_62.66_MB_(100.00 %)
3+ // #Medium #Weekly_Contest_473 #2025_10_28_Time_96_ms_(68.14 %)_Space_62.66_MB_(83.54 %)
44
55import java .util .HashMap ;
66import java .util .Map ;
Original file line number Diff line number Diff line change 11package g3701_3800 .s3729_count_distinct_subarrays_divisible_by_k_in_sorted_array ;
22
3- // #Hard #Weekly_Contest_473 #2025_10_26_Time_67_ms_(50.00%)_Space_61.73_MB_(50.00 %)
3+ // #Hard #Weekly_Contest_473 #2025_10_28_Time_61_ms_(88.70%)_Space_60.47_MB_(80.43 %)
44
55import java .util .HashMap ;
66import java .util .Map ;
You can’t perform that action at this time.
0 commit comments