Skip to content

Commit 172f797

Browse files
authored
Improved tasks 3332, 3337
1 parent 5abefe0 commit 172f797

File tree

2 files changed

+14
-14
lines changed
  • src/main/kotlin/g3301_3400
    • s3332_maximum_points_tourist_can_earn
    • s3337_total_characters_in_string_after_transformations_ii

2 files changed

+14
-14
lines changed

src/main/kotlin/g3301_3400/s3332_maximum_points_tourist_can_earn/Solution.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import kotlin.math.max
88
class Solution {
99
fun maxScore(n: Int, k: Int, stayScores: Array<IntArray>, travelScores: Array<IntArray>): Int {
1010
// dp[day][city]
11-
val dp = Array<IntArray?>(k + 1) { IntArray(n) }
11+
val dp = Array<IntArray>(k + 1) { IntArray(n) }
1212
var result = 0
1313
for (day in k - 1 downTo 0) {
1414
for (city in 0 until n) {
15-
val stayScore = stayScores[day][city] + dp[day + 1]!![city]
15+
val stayScore = stayScores[day][city] + dp[day + 1][city]
1616
var travelScore = 0
1717
for (nextCity in 0 until n) {
18-
val nextScore = travelScores[city][nextCity] + dp[day + 1]!![nextCity]
18+
val nextScore = travelScores[city][nextCity] + dp[day + 1][nextCity]
1919
travelScore = max(nextScore, travelScore)
2020
}
21-
dp[day]!![city] = max(stayScore, travelScore)
22-
result = max(dp[day]!![city], result)
21+
dp[day][city] = max(stayScore, travelScore)
22+
result = max(dp[day][city], result)
2323
}
2424
}
2525
return result

src/main/kotlin/g3301_3400/s3337_total_characters_in_string_after_transformations_ii/Solution.kt

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ package g3301_3400.s3337_total_characters_in_string_after_transformations_ii
55

66
class Solution {
77
fun lengthAfterTransformations(s: String, t: Int, nums: List<Int>): Int {
8-
val m = Array<IntArray?>(26) { IntArray(26) }
8+
val m = Array<IntArray>(26) { IntArray(26) }
99
for (i in 0..25) {
1010
for (j in 1..nums[i]) {
11-
m[(i + j) % 26]!![i] = m[(i + j) % 26]!![i] + 1
11+
m[(i + j) % 26][i] = m[(i + j) % 26][i] + 1
1212
}
1313
}
1414
var v = IntArray(26)
@@ -24,7 +24,7 @@ class Solution {
2424
}
2525

2626
// A^e*v
27-
private fun pow(a: Array<IntArray?>, v: IntArray, e: Long): IntArray {
27+
private fun pow(a: Array<IntArray>, v: IntArray, e: Long): IntArray {
2828
var v = v
2929
var e = e
3030
for (i in v.indices) {
@@ -44,14 +44,14 @@ class Solution {
4444
}
4545

4646
// int matrix*int vector
47-
private fun mul(a: Array<IntArray?>, v: IntArray): IntArray {
47+
private fun mul(a: Array<IntArray>, v: IntArray): IntArray {
4848
val m = a.size
4949
val n = v.size
5050
val w = IntArray(m)
5151
for (i in 0 until m) {
5252
var sum: Long = 0
5353
for (k in 0 until n) {
54-
sum += a[i]!![k].toLong() * v[k]
54+
sum += a[i][k].toLong() * v[k]
5555
if (sum >= BIG) {
5656
sum -= BIG
5757
}
@@ -62,21 +62,21 @@ class Solution {
6262
}
6363

6464
// int matrix^2 (be careful about negative value)
65-
private fun p2(a: Array<IntArray?>): Array<IntArray?> {
65+
private fun p2(a: Array<IntArray>): Array<IntArray> {
6666
val n = a.size
67-
val c = Array<IntArray?>(n) { IntArray(n) }
67+
val c = Array<IntArray>(n) { IntArray(n) }
6868
for (i in 0 until n) {
6969
val sum = LongArray(n)
7070
for (k in 0 until n) {
7171
for (j in 0 until n) {
72-
sum[j] += a[i]!![k].toLong() * a[k]!![j]
72+
sum[j] += a[i][k].toLong() * a[k][j]
7373
if (sum[j] >= BIG) {
7474
sum[j] -= BIG
7575
}
7676
}
7777
}
7878
for (j in 0 until n) {
79-
c[i]!![j] = (sum[j] % MOD).toInt()
79+
c[i][j] = (sum[j] % MOD).toInt()
8080
}
8181
}
8282
return c

0 commit comments

Comments
 (0)