Official
B - 筋トレの目標達成 / Achieving the Muscle Training Goal Editorial by admin
swe-2-highExplanation
For each member, the answer is the position of the first o when scanning the record from left to right. If the first o is at index \(j\) (0-based), that corresponds to day \(j+1\). If no o appears, we output -1.
The program reads the records one line at a time, sets ans to \(-1\), then checks s[j] == 'o' for \(j = 0, 1, \ldots, W-1\). At the first match it sets ans = j + 1 and breaks, so a later o can never overwrite it — ans is truly the first successful day. If nothing matches, ans stays \(-1\).
For each of the \(H\) members we inspect at most \(W\) characters, so the time complexity is \(O(HW)\). Only one string is stored at a time, so the space complexity is \(O(W)\).