Submission #40188501
Source Code Expand
def main():
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
def dfs(current_pos: tuple, visited_numbers: set) -> int:
if current_pos == (H-1, W-1):
return 1
h, w = current_pos
count = 0
if h < H-1:
next_num = A[h+1][w]
if next_num not in visited_numbers:
visited_numbers.add(next_num)
count += dfs((h+1, w), visited_numbers)
visited_numbers.remove(next_num)
if w < W-1:
next_num = A[h][w+1]
if next_num not in visited_numbers:
visited_numbers.add(next_num)
count += dfs((h, w+1), visited_numbers)
visited_numbers.remove(next_num)
return count
print(dfs((0, 0), {A[0][0]}))
main()
Submission Info
| Submission Time | |
|---|---|
| Task | C - Make Takahashi Happy |
| User | Aruma256 |
| Language | Python (3.8.2) |
| Score | 300 |
| Code Size | 868 Byte |
| Status | AC |
| Exec Time | 109 ms |
| Memory | 9080 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, example0.txt, example1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 24 ms | 9080 KiB |
| 001.txt | AC | 19 ms | 9000 KiB |
| 002.txt | AC | 84 ms | 8892 KiB |
| 003.txt | AC | 99 ms | 8888 KiB |
| 004.txt | AC | 20 ms | 8960 KiB |
| 005.txt | AC | 23 ms | 9048 KiB |
| 006.txt | AC | 97 ms | 9016 KiB |
| 007.txt | AC | 19 ms | 9080 KiB |
| 008.txt | AC | 18 ms | 8960 KiB |
| 009.txt | AC | 19 ms | 9072 KiB |
| 010.txt | AC | 97 ms | 8964 KiB |
| 011.txt | AC | 102 ms | 8892 KiB |
| 012.txt | AC | 97 ms | 8984 KiB |
| 013.txt | AC | 93 ms | 8948 KiB |
| 014.txt | AC | 91 ms | 8852 KiB |
| 015.txt | AC | 87 ms | 8936 KiB |
| 016.txt | AC | 54 ms | 8888 KiB |
| 017.txt | AC | 40 ms | 8888 KiB |
| 018.txt | AC | 57 ms | 8892 KiB |
| 019.txt | AC | 60 ms | 8888 KiB |
| 020.txt | AC | 42 ms | 9068 KiB |
| 021.txt | AC | 41 ms | 8948 KiB |
| 022.txt | AC | 43 ms | 8984 KiB |
| example0.txt | AC | 21 ms | 8964 KiB |
| example1.txt | AC | 109 ms | 8940 KiB |