Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
def move_up(row, col): return row - 1, col def move_down(row, col): return row + 1, col def move_left(row, col): return row, col - 1 def move_right(row, col): return row, col + 1 size = int(input()) matrix = [] bunny_row = 0 bunny_col = 0 for row in range(size): row_elements = input().split() matrix.append(row_elements) for col in range(size): if row_elements[col] == "B": bunny_row = row bunny_col = col directions = { "up": move_up, "down": move_down, "left": move_left, "right": move_right } best_sum = float("-inf") best_direction = "" best_path = [] for direction, step in directions.items(): current_row, current_col = bunny_row, bunny_col path = [] current_sum = 0 while True: current_row, current_col = step(current_row, current_col) # извиквам функцията if current_row < 0 or current_col < 0 or current_row >= size or current_col >= size or matrix[current_row][current_col] == "X": break path.append([current_row, current_col]) current_sum += int(matrix[current_row][current_col]) if current_sum > best_sum and path: best_sum = current_sum best_direction = direction best_path = path print(best_direction) for path in best_path: print(path) print(best_sum)
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)