Wrong Answer
Code
def min_operations(N):
dp = [float('inf')] * (N + 1) # Initialize dp array with infinity
dp[0] = 0 # Base case: zero operations needed for 0
for i in range(2, N + 1):
if i >= 2:
dp[i] = min(dp[i], dp[i - 2] + 1) # Subtract 2 operation
if i >= 3:
dp[i] = min(dp[i], dp[i - 3] + 1) # Subtract 3 operation
return dp[N] if dp[N] != float('inf') else -1 # Return -1 if no solution
# Example usage
N = int(input("Enter the integer N: "))
print("Minimum number of operations:", min_operations(N))
Information
- Submit By
- Type
- Submission
- Problem
- P1106 too easy or three easy
- Language
- Python 3 (Python 3.12.3)
- Submit At
- 2024-11-03 08:54:46
- Judged At
- 2024-11-11 02:34:06
- Judged By
- Score
- 0
- Total Time
- 15ms
- Peak Memory
- 3.035 MiB