Official

B - Most Minority Editorial by physics0523


この問題で要求されていることは以下の通りです。

  • 全ての投票を一度保存する。
  • 各投票について誰が得点を得たかを判定し、各人の合計得点を求める。
  • 得点が最大の人を全員求める。

一連の操作は、 for 文を用いて実装可能です。

実装例 (C++):

#include<bits/stdc++.h>

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  vector<string> s(n);
  for(auto &nx : s){cin >> nx;}
  
  vector<int> pt(n,0);
  for(int j=0;j<m;j++){
    int x=0,y=0;
    for(int i=0;i<n;i++){
      if(s[i][j]=='0'){x++;}
      else{y++;}
    }
    for(int i=0;i<n;i++){
      if(s[i][j]=='0'){
        if(x<=y){pt[i]++;}
      }
      else{
        if(x>=y){pt[i]++;}
      }
    }
  }
  
  int high=(*max_element(pt.begin(),pt.end()));
  bool spc=false;
  for(int i=0;i<n;i++){
    if(pt[i]==high){
      if(spc){cout << " ";}
      cout << i+1;
      spc=true;
    }
  }cout << "\n";
  return 0;
}

posted:
last update: