TLE10分:实在不知道该怎么缩短时间了
#include<bits/stdc++.h>
using namespace std;
int const M=1e4+10;
char c[M][11];
int a[M][11],b[M][11];
struct vote
{
int number,p;
}x[M];
bool cmp(vote a,vote b)
{
if(a.number!=b.number)return a.number>b.number;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int n,m,temp,t;
cin>>m>>n;
int k=m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>c[i][j];
if(c[i][j]=='0')break;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(c[i][j])
{
a[i][j]=c[i][j]-'0';
if(a[i][j])b[i][j]=1;
}
}
}
while(true)
{
memset(x,0,sizeof(x));
for(int i=1;i<=9;i++)x[i].p=i;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(b[i][j])
{
x[a[i][j]].number++;
if(x[a[i][j]].number>(n+1)/2)
{
cout<<a[i][j]<<endl;
return 0;
}
break;
}
}
}
sort(x+1,x+1+9,cmp);
if(x[k].number==x[1].number)
{
cout<<-x[1].number<<endl;
return 0;
}
}
return 0;
}