PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000351. Tổng chia hết theo modulo (Modulo Sum)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng chia hết theo modulo (Modulo Sum)
Modulo Sum
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given nonnegative integers and a positive modulus , determine whether one can select at least one distinct index so that the sum of the selected values is divisible by . The selected indices form a subsequence and need not be consecutive.
The empty subsequence is forbidden. Each position can be selected at most once; equal values at different indices remain distinct choices.
Input
- First line: integers .
- Second line: the integers .
Output
Print YES if such a nonempty subsequence exists; otherwise print NO.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
3 5
1 2 3
Output
YES
Explanation
Choose values 2 and 3: the sum 5 is divisible by 5.
Example 2
Input
1 6
5
Output
NO
Explanation
The only nonempty subsequence is [5], whose sum leaves remainder 5 modulo 6.
Example 3
Input
4 6
3 1 1 3
Output
YES
Explanation
Choose the first and last elements: 3+3=6; their indices differ.