Translation Notice
This article was machine-translated using DeepSeek-R1.
- Original Version: Authored in Chinese by myself
- Accuracy Advisory: Potential discrepancies may exist between translations
- Precedence: The Chinese text shall prevail in case of ambiguity
- Feedback: Technical suggestions regarding translation quality are welcomed
A - Don’t be late
Problem Statement
Takahashi plans to meet Aoki.
They will meet at a location $D$ meters away from Takahashi’s house in $T$ minutes.
Takahashi will leave immediately and walk towards the meeting point at a speed of $S$ meters per minute.
Can Takahashi arrive on time?
$1\le D\le 10000$
$1\le T\le 10000$
$1\le S\le 10000$
Input Format
$D~T~S$
Output Format
Print Yes
if Takahashi arrives on time or early; otherwise print No
.
Samples
D | T | S | Output |
---|---|---|---|
1000 | 15 | 80 | Yes |
2000 | 20 | 100 | Yes |
10000 | 1 | 1 | No |
Analysis
Check whether $\frac D S\le T$ (simplified as $TS\ge D$).
Code
|
|
B - Substring
Problem Statement
Given two strings $S$ and $T$.
Modify some characters in $S$ (possibly none) to make $T$ a substring of $S$.
What is the minimum number of characters to modify?
Substring: e.g., xxx
is a substring of yxxxy
but not of xxyxx
.
$1\le |T|\le |S|\le 1000$
$S$ and $T$ consist of lowercase English letters.
Input Format
$S~T$
Output Format
Print the minimum number of characters to modify.
Samples
Sample Input1
|
|
Sample Output1
|
|
Sample Input2
|
|
Sample Output2
|
|
Analysis
Slide $T$ over $S$ and find the position with the minimum number of differing characters.
Code
This is essentially brute force enumeration :)
Note: If following the code below, ensure to handle the case where $S$ and $T$ have equal lengths first!
|
|
C - Sum of product of pairs
Problem Statement
Given $N$ integers $A_1,A_2,\dots,A_N$.
Compute ${\sum\limits_{i=1}^{N-1}\sum\limits_{j=i+1}^NA_iA_j} \mod {(10^9+7)}$, i.e., the sum of products of all pairs $(i,j)$ where $1\le i \lt j\le N$, modulo $(10^9 + 7)$.
Input Format
$N$
$A_1~A_2~\dots~A_N$
Output Format
Print the result.
Samples
Sample Input1
|
|
Sample Output1
|
|
$1\times2+1\times3+2\times3=11$.
Sample Input2
|
|
Sample Output2
|
|
Don’t forget to take modulo $(10^9 + 7)$!
Analysis
$${\sum\limits_{i=1}^{N-1}\sum\limits_{j=i+1}^NA_iA_j} \mod {(10^9+7)}$$$${(\sum\limits_{i=2}^{N}\sum\limits_{j=0}^{i-1}A_iA_j)} \mod {(10^9+7)}$$$${\sum\limits_{i=2}^{N}A_i(\sum\limits_{j=0}^{i-1}A_j)} \mod {(10^9+7)}$$
Maintain a cumulative sum while iterating through the array.
Code
Process input incrementally.
Use long long
despite modulo operations:
|
|
D - Friends
Problem Statement
There are $N$ people numbered $1$ to $N$.
Given $M$ relationships, where the $i$-th states “Person $A_i$ and $B_i$ are friends.” (may contain duplicates).
If $X$ and $Y$ are friends, and $Y$ and $Z$ are friends, then $X$ and $Z$ are friends.
Takahashi wants to divide these people into groups where no two people in the same group are friends. What is the minimum number of groups required?
$2\le N\le 2\times10^5$
$0\le M\le 2\times10^5$
$1\le A_i,B_i\le N$
$A_i \ne B_i$
Input Format
$N~M$
$A_1~B_1$
$A_2~B_2$
$\vdots$
$A_M~B_M$
Output Format
Print the answer.
Samples
Sample Input1
|
|
Sample Output1
|
|
Three groups: $\{1,3\}$, $\{2,4\}$, $\{5\}$.
Sample Input2
|
|
Sample Output2
|
|
Note duplicate relationships.
Sample Input3
|
|
Sample Output3
|
|
Analysis
Find all connected components (friend circles) and output the size of the largest component.
Code
Use BFS/DFS or Union-Find to find connected components. Here BFS is implemented.
|
|