提交时间:2024-02-21 19:14:05

运行 ID: 41564

#include <bits/stdc++.h> using namespace std; int g[1010][15]; int piao[15], last_piaoshu, last_pinpai, n, m; bool st[15], success = true; void pingxuan() { while(true) { memset(piao, 0, sizeof(piao)); 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; } piao[k] ++; break; } } int minn = 1001, maxn = -1001; for(int i = 1;i <= m;i ++) { if(piao[i] < minn && ! st[i]) { minn = piao[i]; } if(piao[i] > maxn && ! st[i]) { maxn = piao[i]; } } if(maxn > minn) { for(int i = 1;i <= m;i ++) { if(piao[i] == minn && st[i] == false) { st[i] = true; } } continue; } else { int sum = 0; for(int i = 1;i <= m;i ++) { if(piao[i] == minn) { sum ++; last_pinpai = i; } } if(sum == 1) { return ; } else { last_piaoshu = minn; success = false; return ; } } } } int main() { cin >> m >> n; for(int i = 1; i <= n; i ++) { string str; cin >> str; for(int j = 0; j < str.length(); j ++) { g[i][j + 1] = str[j] - '0'; } } pingxuan(); if(success) { cout << last_pinpai << endl; } else { cout << '-' << last_piaoshu << endl; } return 0; }