A - 注文の確認 / Order Confirmation Editorial by admin
gpt-5.3-codexOverview
For each customer, simply compare the actual order \(T_i\) with the communicated order \(S_i\) as a pair, and count the number of pairs that differ. In other words, you just need to find “the number of \(i\) such that \(T_i \neq S_i\).”
Analysis
The key observation is simple: the determination for each customer is independent of the other customers. Therefore, no complex data structures or sorting are needed throughout the entire process — the problem can be solved by simply reading each line, comparing, and counting.
For example, consider the following input:
- \((T_1, S_1) = (\text{ramen}, \text{ramen})\) → match (do not count)
- \((T_2, S_2) = (\text{sushi}, \text{susi})\) → mismatch (+1)
- \((T_3, S_3) = (\text{curry}, \text{curry})\) → match
The answer is 1.
As a naive approach, you could store all pairs in an array and process them later, but that is unnecessary for this problem. You can simply compare each pair as you read the input, which also saves memory. Since \(N \le 10^5\), an \(O(N)\) solution that compares one pair at a time is sufficiently fast.
Algorithm
- Read the integer \(N\).
- Initialize a variable
ans = 0(the count of mistakes). - Repeat \(N\) times:
- Read strings
t, s. - If
t != s, thenans += 1.
- Read strings
- Finally, output
ans.
The provided code is a direct implementation of this.
Complexity
- Time complexity: \(O(N)\) (because one string comparison is performed per line)
- Space complexity: \(O(1)\) (because the input is not stored; each pair is checked on the spot)
Implementation Notes
Since the number of inputs can be up to \(10^5\), using
sys.stdin.readlinein Python ensures consistently fast reading.Each line can be split into the two values
t, susinginput().split().The comparison condition is simply
if t != s:— that’s all you need.Source Code
import sys
def main():
input = sys.stdin.readline
n = int(input().strip())
ans = 0
for _ in range(n):
t, s = input().split()
if t != s:
ans += 1
print(ans)
if __name__ == "__main__":
main()
This editorial was generated by gpt-5.3-codex.
posted:
last update: