답안 #1087928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087928 2024-09-13T14:39:39 Z idk__ Izbori (COCI17_izbori) C++14
80 / 80
420 ms 348 KB
#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

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;
      |                            ~~~~~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 348 KB Output is correct
2 Correct 24 ms 344 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 55 ms 348 KB Output is correct
5 Correct 9 ms 348 KB Output is correct
6 Correct 6 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 34 ms 348 KB Output is correct
9 Correct 29 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 25 ms 348 KB Output is correct
12 Correct 150 ms 348 KB Output is correct
13 Correct 337 ms 344 KB Output is correct
14 Correct 146 ms 344 KB Output is correct
15 Correct 26 ms 348 KB Output is correct
16 Correct 420 ms 348 KB Output is correct
17 Correct 170 ms 344 KB Output is correct
18 Correct 355 ms 348 KB Output is correct
19 Correct 398 ms 348 KB Output is correct
20 Correct 401 ms 344 KB Output is correct