Submission #1087895

# Submission time Handle Problem Language Result Execution time Memory
1087895 2024-09-13T11:17:13 Z vjudge1 Izbori (COCI17_izbori) C++17
80 / 80
31 ms 472 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define speed cin.tie (0) -> sync_with_stdio (0);ios_base::sync_with_stdio(false);cin.tie(0);
vector<int> v;
int n, m, k;
int a[105][20];
int ans = 1e9;
bool check()
{
    bool vis[m + 5] = {};
    for(auto i : v) vis[i] = 1;
    
    int f[m + 5] = {};
    pair<int, int> cur = {0, 0};
    for(int i=0; i<n; i++)
    {
        int x = 0;
        while (x < m && vis[a[i][x]]) x++;
        if (x == m) continue;
        f[a[i][x]]++;
        
        if (f[a[i][x]] > cur.first || (f[a[i][x]] == cur.first && a[i][x] < cur.second)) cur = {f[a[i][x]], a[i][x]};
    }
    
    if (cur.first != 0) return (cur.second == k);
    return 0;
}
void rec(int i, int cnt)
{
    if (i == m)
    {
        // for(auto i : v) cout<<i<<" ";
        // cout<<endl;
        bool x = check();
        // cout<<x<<endl;
        
        if (x) ans = min(ans, cnt);
        return;
    }
    
    v.push_back(i + 1);
    rec(i + 1, cnt + 1);
    v.pop_back();
    rec(i + 1, cnt);
}
void solve()
{
    cin>>n>>m>>k;
    
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            cin>>a[i][j];
        }
    }
    
    int ff[m + 5] = {};
    pair<int, int> mx = {0, 0};
    for(int i=0; i<n; i++)
    {
        ff[a[i][0]]++;
        if (ff[a[i][0]] > mx.first || (ff[a[i][0]] == mx.first && a[i][0] < mx.second)) mx = {ff[a[i][0]], a[i][0]};
    }
    cout<<mx.second<<endl;
    rec(0, 0);
    cout<<ans<<endl;
}
signed main ()
{
    speed
    // freopen("feast.in", "r", stdin);
    // freopen("feast.out", "w", stdout);

    int _ = 1;
    // cin>>_;

    while(_--) solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 8 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 14 ms 344 KB Output is correct
13 Correct 28 ms 348 KB Output is correct
14 Correct 13 ms 344 KB Output is correct
15 Correct 4 ms 472 KB Output is correct
16 Correct 31 ms 348 KB Output is correct
17 Correct 15 ms 344 KB Output is correct
18 Correct 23 ms 348 KB Output is correct
19 Correct 27 ms 348 KB Output is correct
20 Correct 29 ms 348 KB Output is correct