Submission #1087928

#TimeUsernameProblemLanguageResultExecution timeMemory
1087928idk__Izbori (COCI17_izbori)C++14
80 / 80
420 ms348 KiB
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define int long long
int a[101][16+5], n, m , k;
vector<int>temp;


int winner(){
    int b[100][16+5]={};
    for(int i = 0;i < n; i++){
        for(int j = 0;j < m; j++){
            b[i][j] = a[i][j];
        }
    }
        for(auto cv : temp){
            for(int i = 0;i < n; i++){
                for(int j = 0;j < m; j++){
                    if(b[i][j]==cv)b[i][j]=-5;
                }
            }
        }
    

    int count=-1, num=-1;
    int cnt[16]={}, poi[n+5]={};
    for(int i = 0;i < n; i++){
        while(true){
            if(b[i][poi[i]]==-5)poi[i]++;
            else break;
            if(poi[i]>m)break;
        }
        int& curr = b[i][poi[i]];
        if(poi[i]>=m)continue;


        cnt[curr]++;
        if(cnt[curr] > count){
            num = curr;
            count=cnt[curr];
        }
        else if(cnt[curr] == count and curr < num){
                num = curr;
                count = cnt[curr];
        }

        }
        
        return  num;
}
pair<int, int>fans = {1000, 1000};
void rec(int i){

    if(i==m+1){
        pair<int, int>f = {temp.size(), winner()};
        if(f.second==k and temp.size() < fans.first)fans = f;
        return;
    }

    rec(i+1);
    temp.push_back(i);
    rec(i+1);
    temp.pop_back();
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m >> k;
    for(int i = 0;i < n; i++){
        for(int j = 0;j < m; j++){
            cin >> a[i][j];
        }
    }

    int ans = winner();
    cout << ans << endl;
    rec(1);
    cout << fans.first << endl;

    
  
  
  
  
  }

Compilation message (stderr)

izbori.cpp: In function 'void rec(long long int)':
izbori.cpp:57:40: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   57 |         if(f.second==k and temp.size() < fans.first)fans = f;
      |                            ~~~~~~~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...