提交时间:2024-02-21 18:38:52

运行 ID: 41522

#include<bits/stdc++.h> using namespace std; int g[1010][15]; int p[15]; bool st[15]; bool s=true; int ps; int pp; int n,m; void px() { while(1){ memset(p,0,sizeof(p)); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ int k=g[i][j]; if(k==0) break; if(st[k]) continue; p[k]++; break; } } int minn=1001,maxn=-1001; for(int i=1;i<m;i++){ if(p[i]<minn&&!st[i]) minn=p[i]; if(p[i]>maxn&&!st[i]) maxn=p[i]; } if(maxn>minn){ for(int i=1;i<=m;i++){ if(p[i]==minn&&st[i]==false) st[i]=true; } continue; } else{ int su=0; for(int i=1;i<=m;i++){ if(p[i]==minn) s++,pp=i; } if(su==1) return; else { ps==minn; s=false; return ; } } } } int main() { cin>>m>>n; for(int i=1;i<=n;i++){ string str; cin>>str; for(int j=1;j<=m;j++){ g[i][j+1]=str[j]-'0'; } } px(); if(s) cout<<pp<<endl; else cout<<'-'<<ps; return 0; }