Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import kotlin.math.max
class Solution {
fun maxScore(n: Int, k: Int, stayScores: Array<IntArray>, travelScores: Array<IntArray>): Int {
// dp[day][city]
val dp = Array<IntArray?>(k + 1) { IntArray(n) }
val dp = Array<IntArray>(k + 1) { IntArray(n) }
var result = 0
for (day in k - 1 downTo 0) {
for (city in 0 until n) {
val stayScore = stayScores[day][city] + dp[day + 1]!![city]
val stayScore = stayScores[day][city] + dp[day + 1][city]
var travelScore = 0
for (nextCity in 0 until n) {
val nextScore = travelScores[city][nextCity] + dp[day + 1]!![nextCity]
val nextScore = travelScores[city][nextCity] + dp[day + 1][nextCity]
travelScore = max(nextScore, travelScore)
}
dp[day]!![city] = max(stayScore, travelScore)
result = max(dp[day]!![city], result)
dp[day][city] = max(stayScore, travelScore)
result = max(dp[day][city], result)
}
}
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package g3301_3400.s3337_total_characters_in_string_after_transformations_ii

class Solution {
fun lengthAfterTransformations(s: String, t: Int, nums: List<Int>): Int {
val m = Array<IntArray?>(26) { IntArray(26) }
val m = Array<IntArray>(26) { IntArray(26) }
for (i in 0..25) {
for (j in 1..nums[i]) {
m[(i + j) % 26]!![i] = m[(i + j) % 26]!![i] + 1
m[(i + j) % 26][i] = m[(i + j) % 26][i] + 1
}
}
var v = IntArray(26)
Expand All @@ -24,7 +24,7 @@ class Solution {
}

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

// int matrix*int vector
private fun mul(a: Array<IntArray?>, v: IntArray): IntArray {
private fun mul(a: Array<IntArray>, v: IntArray): IntArray {
val m = a.size
val n = v.size
val w = IntArray(m)
for (i in 0 until m) {
var sum: Long = 0
for (k in 0 until n) {
sum += a[i]!![k].toLong() * v[k]
sum += a[i][k].toLong() * v[k]
if (sum >= BIG) {
sum -= BIG
}
Expand All @@ -62,21 +62,21 @@ class Solution {
}

// int matrix^2 (be careful about negative value)
private fun p2(a: Array<IntArray?>): Array<IntArray?> {
private fun p2(a: Array<IntArray>): Array<IntArray> {
val n = a.size
val c = Array<IntArray?>(n) { IntArray(n) }
val c = Array<IntArray>(n) { IntArray(n) }
for (i in 0 until n) {
val sum = LongArray(n)
for (k in 0 until n) {
for (j in 0 until n) {
sum[j] += a[i]!![k].toLong() * a[k]!![j]
sum[j] += a[i][k].toLong() * a[k][j]
if (sum[j] >= BIG) {
sum[j] -= BIG
}
}
}
for (j in 0 until n) {
c[i]!![j] = (sum[j] % MOD).toInt()
c[i][j] = (sum[j] % MOD).toInt()
}
}
return c
Expand Down