A - 朗読の評価 / Evaluation of Reading Aloud Editorial by admin Editorial for printing
gpt-6-astra-mediumOverview
For each student, determine whether their voice loudness and reading speed satisfy the conditions. Append each rating to a string in the order of the students, and print it all together at the end.
Analysis
To be considered a “good recitation”, both of the following conditions must be satisfied:
- Voice loudness is \(A_i \geq X\)
- Reading speed is \(B_i \leq Y\)
Conversely, if either condition is not satisfied, the rating is B. In the presented code, the cases where the conditions are not satisfied are checked first:
- If \(A_i < X\), the voice is too quiet, so the rating is
B - Otherwise, if \(B_i > Y\), the reading speed exceeds the threshold, so the rating is
B - If neither applies, the rating is
G
For example, when \(X=5\) and \(Y=7\), the evaluations are as follows:
| Voice loudness \(A_i\) | Reading speed \(B_i\) | Rating | Reason |
|---|---|---|---|
| 5 | 7 | G |
Satisfies both conditions |
| 4 | 6 | B |
Voice loudness is below the threshold |
| 8 | 9 | B |
Reading speed exceeds the threshold |
Since each student’s evaluation does not depend on the other students, a straightforward approach that evaluates each student one by one in the order of input is sufficient. Since \(N \leq 100\), the execution time is not an issue.
However, mistaking “satisfies both” for “satisfies either”, or classifying values equal to the thresholds as B, will lead to a wrong answer.
Algorithm
- Read \(N, X, Y\), and initialize an empty string
sto store the answer. - For each student, perform the following in the order of input:
- Read \(A_i, B_i\).
- If \(A_i < X\), append
Btos. - Otherwise, if \(B_i > Y\), append
Btos. - Otherwise, append
Gtos.
- Output the completed string
s.
Since exactly one character is appended per student, a string of length \(N\) representing the ratings in the order of the students will be obtained.
Complexity
- Time complexity: \(O(N)\)
For each student, a constant number of comparisons and a single character append are performed. - Space complexity: \(O(N)\)
Stores the rating string of length \(N\). It is not necessary to store all input data.
Implementation Notes
“Greater than or equal to” and “less than or equal to” include equality. \(A_i=X\) and \(B_i=Y\) satisfy their respective conditions.
By using
if,else if, andelse, you can ensure that exactly one character is appended for each student.Output the ratings as a single string without spaces between them.
Source Code
// 問題文から独立に実装: 悪い条件を先に判定
#include <iostream>
#include <string>
int main() {
int n, x, y; std::cin >> n >> x >> y;
std::string s;
for (int i = 0; i < n; ++i) {
int a, b; std::cin >> a >> b;
if (a < x) s += 'B';
else if (b > y) s += 'B';
else s += 'G';
}
std::cout << s << std::endl;
}
This editorial was generated by gpt-6-astra-medium.
posted:
last update: