답안 #475381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475381 2021-09-22T08:57:54 Z HossamHero7 Izbori (COCI17_izbori) C++14
80 / 80
62 ms 324 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
void solve(){
    int n,m,k;
    cin>>n>>m>>k;
    vector <vector<int>> v(n,vector<int>(m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++) cin>>v[i][j];
    }
    for(int i=0;i<m;i++){
        map <int,int> mp;
        for(int j=0;j<n;j++){
            int x = v[j][i];
            mp[x] ++;
        }
        if(i == 0){
        ll ans = 0;
        int mx = 0;
        for(auto j : mp){
            mx = max(mx,j.second);
        }
        for(auto j:mp){
            if(j.second == mx){
                ans = j.first;
                break;
            }
        }
        cout<<ans<<endl;
        }
    }
    int ans2=m;
    for(int mask=1;mask<(1<<m);mask++){
        vector <int> vis(m+1);
        int cnt = 0;
        for(int i=0;i<m;i++){
            int take = (1<<i)&mask;
            if(take) vis[i+1] = 1;
            else cnt ++;
        }
        int ans = m;
        int mx = 0;
        vector <int> temp;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(vis[v[i][j]]) {
                    temp.push_back(v[i][j]);
                    break;
                }
            }
        }
        vector <int> frq(m+1);
        for(auto i : temp) frq[i] ++;
        for(int i=1;i<=m;i++){
            mx = max(mx,frq[i]);
        }
        for(int i=1;i<=m;i++){
            if(frq[i] == mx){
                ans = i;
                break;
            }
        }
        if(ans == k){
            ans2 = min(ans2,cnt);
        }
    }
    cout<<ans2<<endl;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 204 KB Output is correct
2 Correct 10 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 14 ms 208 KB Output is correct
5 Correct 4 ms 204 KB Output is correct
6 Correct 3 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 11 ms 204 KB Output is correct
9 Correct 8 ms 324 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 7 ms 204 KB Output is correct
12 Correct 30 ms 204 KB Output is correct
13 Correct 53 ms 300 KB Output is correct
14 Correct 27 ms 204 KB Output is correct
15 Correct 9 ms 320 KB Output is correct
16 Correct 61 ms 204 KB Output is correct
17 Correct 28 ms 204 KB Output is correct
18 Correct 58 ms 204 KB Output is correct
19 Correct 62 ms 204 KB Output is correct
20 Correct 61 ms 204 KB Output is correct