公式

B - 饂飩屋の席 / Seats in an Udon Restaurant 解説 by kyopro_friends


上の行から順にいくつの空席があるかを求め、最大値が更新されるたびに暫定答えを更新していけば良いです。

実装例 (C++)

#include<bits/stdc++.h>
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0; i<h; i++) cin >> s[i];

  int M = -1, ans = -1;
  for(int i=0; i<h; i++){
    int cnt = count(s[i].begin(), s[i].end(), '.');
    if(cnt > M){
      M = cnt;
      ans = i + 1;
    }
  }
  cout << ans << endl;
}

実装例 (Python)

H, W = map(int, input().split())
S = [input() for _ in range(H)]

M = -1
ans = -1
for i, s in enumerate(S):
  count = s.count(".")
  if count > M:
    M = count 
    ans = i + 1

print(ans)