fix it fix this code def saminstringfactor(saX, saY, saS, saR): salenx = len(saX) saleny…
Jump to turn (7)
- 1fix it fix this code def saminstringfactor(saX, saY, saS, saR): salenx = len(saX
- 2remove comment
- 3wrong answer for both see the question XFromYMarks: 30 Problem Description Malai
- 4fix it
- 5fix this when i sented you my ver it was working but it not
- 6still errro
- 7one is wrong error and another presentation erro
- User
fix it fix this code def sa_min_string_factor(sa_X, sa_Y, sa_S, sa_R): sa_len_x = len(sa_X) sa_len_y = len(sa_Y) sa_dp = [float('inf')] * (sa_len_x + 1) sa_dp[0] = 0 sa_substrings_y = set() sa_substrings_rev_y = set() for sa_start in range(sa_len_y): for sa_end in range(sa_start + 1, sa_len_y + 1): sa_substrings_y.add(sa_Y[sa_start:sa_end]) sa_substrings_rev_y.add(sa_Y[::-1][sa_start:sa_end]) for sa_i in range(sa_len_x): for sa_length in range(1, sa_len_y + 1): if sa_i + sa_length > sa_len_x: break sa_sub_x = sa_X[sa_i:sa_i + sa_length] if sa_sub_x in sa_substrings_y: sa_dp[sa_i + sa_length] = min(sa_dp[sa_i + sa_length], sa_dp[sa_i] + sa_S) if sa_sub_x in sa_substrings_rev_y: sa_dp[sa_i + sa_length] = min(sa_dp[sa_i + sa_length], sa_dp[sa_i] + sa_R) return sa_dp[sa_len_x] if sa_dp[sa_len_x] != float('inf') else "Impossible" def main(): import sys input = sys.stdin.read sa_lines = input().strip().split("\n") sa_X = sa_lines[0].strip() sa_Y = sa_lines[1].strip() sa_S, sa_R = map(int, sa_lines[2].strip().split())
sa_result = sa_min_string_factor(sa_X, sa_Y, sa_S, sa_R) print(sa_result, end='') if name == "main": main() make it powerful mean no tle and memory
- Assistant