PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000288. Trò chơi nhảy VII (Jump Game VII)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Trò chơi nhảy VII (Jump Game VII)
Jump Game VII
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A binary string of length is indexed from 0 to , with . Starting at index 0, a jump from to is allowed when and . Determine whether index is reachable.
Input
First line: . Second line: the string of exactly binary characters, without spaces.
Output
Print lowercase true if the final index is reachable, or false otherwise.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Example 1
Input
6 2 3
011010
Output
true
Explanation
The path 0→3→5 uses jumps of length 3 and 2.
Example 2
Input
8 2 3
01101110
Output
false
Explanation
From 0 only index 3 is reachable; both indices 5 and 6 are blocked.