Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 21f0e9c

Browse files
authored
Improved tasks 3218, 3219, 3220
1 parent 20ff7b7 commit 21f0e9c

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

‎src/main/java/g3201_3300/s3218_minimum_cost_for_cutting_cake_i/Solution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
// #Medium #Array #Dynamic_Programming #Sorting #Greedy
44
// #2024_07_18_Time_0_ms_(100.00%)_Space_42.4_MB_(32.85%)
55

6+
@SuppressWarnings("java:S1172")
67
public class Solution {
7-
public int minimumCost(int ignoredM, int ignoredN, int[] horizontalCut, int[] verticalCut) {
8+
public int minimumCost(int m, int n, int[] horizontalCut, int[] verticalCut) {
89
int sum = 0;
910
for (int hc : horizontalCut) {
1011
sum += hc;

‎src/main/java/g3201_3300/s3219_minimum_cost_for_cutting_cake_ii/Solution.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,36 @@
22

33
// #Hard #Array #Sorting #Greedy #2024_07_18_Time_3_ms_(100.00%)_Space_62.6_MB_(25.82%)
44

5+
@SuppressWarnings("java:S1172")
56
public class Solution {
67
private static final int N = 1001;
7-
private static final int[] HORIZONTAL_COUNTS = new int[N];
8-
private static final int[] VERTICAL_COUNTS = new int[N];
98

109
public long minimumCost(int m, int n, int[] horizontalCut, int[] verticalCut) {
10+
int[] horizontalCounts = new int[N];
11+
int[] verticalCounts = new int[N];
1112
int max = 0;
1213
for (int x : horizontalCut) {
1314
if (x > max) {
1415
max = x;
1516
}
16-
HORIZONTAL_COUNTS[x]++;
17+
horizontalCounts[x]++;
1718
}
1819
for (int x : verticalCut) {
1920
if (x > max) {
2021
max = x;
2122
}
22-
VERTICAL_COUNTS[x]++;
23+
verticalCounts[x]++;
2324
}
2425
long ans = 0;
2526
int horizontalCount = 1;
2627
int verticalCount = 1;
2728
for (int x = max; x > 0; x--) {
28-
ans += (long) HORIZONTAL_COUNTS[x] * x * horizontalCount;
29-
verticalCount += HORIZONTAL_COUNTS[x];
30-
HORIZONTAL_COUNTS[x] = 0;
31-
ans += (long) VERTICAL_COUNTS[x] * x * verticalCount;
32-
horizontalCount += VERTICAL_COUNTS[x];
33-
VERTICAL_COUNTS[x] = 0;
29+
ans += (long) horizontalCounts[x] * x * horizontalCount;
30+
verticalCount += horizontalCounts[x];
31+
horizontalCounts[x] = 0;
32+
ans += (long) verticalCounts[x] * x * verticalCount;
33+
horizontalCount += verticalCounts[x];
34+
verticalCounts[x] = 0;
3435
}
3536
return ans;
3637
}

‎src/main/java/g3201_3300/s3220_odd_and_even_transactions/script.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
select transaction_date,
44
sum(case when amount%2<>0 then amount else 0 end) as odd_sum,
55
sum(case when amount%2=0 then amount else 0 end) as even_sum from transactions
6-
group by transaction_date order by transaction_date;
6+
group by transaction_date order by transaction_dateasc;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /