1 solutions

  • 0
    @ 2024-10-16 15:48:05
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N =1e6+5;
    string v[15];
    bool vis[15];
    int cou[15];
    int m, n;
    int cnt = 0;
    bool solve() {
    	memset(cou, 0, sizeof(cou));
    	int x;
    	for(int i = 0; i < n; i++){
    		for(int j = 0; j < v[i].size(); j++){
    			x = v[i][j] - '0';
    			if(!x) break;
    			if(!vis[x]) {
    				cou[x]++;
    				break;
    			}
    		}
    	}
    	int mn = 100;
    	cou[mn] = 0x3f3f3f3f;
    	vector <int> del;
    	for(int i = 1; i <= m; i++){
    		if(vis[i]) continue;
    		if(cou[i] < cou[mn]) {
    			mn = i;
    			del.clear();
    			del.push_back(i);
    		}
    		else if(cou[i] == cou[mn]) {
    			del.push_back(i);
    		}
    	}
    	if(m - cnt - del.size() == 1) {
    		for(int i = 1; i <= m; i++){
    			if(!vis[i] && i != mn) {
    				cout << i;
    				break;
    			}
    		}
    		return false;
    	} else if(m - cnt - del.size() > 0) {
    		cnt += del.size();
    		for(auto x : del) {
    			vis[x] = 1;
    		}
    		return true;
    	} else if (m - cnt - del.size() == 0 ) {
    		cout << -cou[mn];
    		return false;
    	} 
    
    }
    
    int main(){
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    
    	
    	cin >> m >> n;
    	for(int i = 0; i < n; i++){
    		cin >> v[i];
    	}
    	
    	while(solve()){
    		
    	}
    
    
    	return 0;
    }
    
    

    Information

    ID
    1284
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    7
    Accepted
    3
    Uploaded By