답안 #651403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
651403 2022-10-18T17:14:31 Z BidoTeima Izbori (COCI17_izbori) C++17
64 / 80
18 ms 340 KB
/*
ID: BidoTeima
LANG: C++11
TASK: Izbori
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void moo(string filename);
void ACPLS(string str = "")
{
    if(str=="NOF")return;
    if(str.size())
        moo(str);
    else{
        #ifndef ONLINE_JUDGE
            freopen("output.txt", "w", stdout);
            freopen("input.txt", "r", stdin);
        #endif
    }
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void moo(string fileName){
    freopen((fileName+".in").c_str(),"r",stdin);
    freopen((fileName+".out").c_str(),"w",stdout);
}
#define tc         \
    int tttttt/*,subtask*/;    \
    cin >> tttttt/* >> subtask*/; \
    while (tttttt--)/*end
*/    

int main()
{
    //ACPLS("");
    int n,m,k;
    cin>>n>>m>>k;
    vector<vector<int>>a(n,vector<int>(m));
    int f[m+1]={0};
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin>>a[i][j];
            if(j == 0)
                ++f[a[i][j]];
        } 
    }
    int winner = 1;
    for(int i = 1; i <= m; i++){
        if(f[i] > f[winner])
            winner = i;
    }
    cout<<winner<<'\n';
    bool vis[m+1]={0};
    int ans = m-1;
    for(int i = 0; i < (1<<m); i++){
        if(i&(1<<k))continue;
        int freq[m+1]={0};
        for(int j = 0; j < n; j++){
            for(int k = 0; k < m; k++){
                if(!(i&(1<<a[j][k]))){
                    ++freq[a[j][k]];
                    break;
                }
            }
        }
        if(max_element(freq+1,freq+m+1)-freq == k){
            ans=min(ans,__builtin_popcount(i));
        }
    }
    cout<<ans<<'\n';
}

Compilation message

izbori.cpp: In function 'int main()':
izbori.cpp:55:10: warning: unused variable 'vis' [-Wunused-variable]
   55 |     bool vis[m+1]={0};
      |          ^~~
izbori.cpp: In function 'void ACPLS(std::string)':
izbori.cpp:17:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |             freopen("output.txt", "w", stdout);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
izbori.cpp:18:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |             freopen("input.txt", "r", stdin);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
izbori.cpp: In function 'void moo(std::string)':
izbori.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((fileName+".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
izbori.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((fileName+".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 212 KB Partially correct
2 Correct 1 ms 212 KB Output is correct
3 Partially correct 1 ms 212 KB Partially correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Partially correct 2 ms 212 KB Partially correct
9 Partially correct 3 ms 212 KB Partially correct
10 Partially correct 1 ms 212 KB Partially correct
11 Correct 2 ms 212 KB Output is correct
12 Correct 7 ms 212 KB Output is correct
13 Partially correct 12 ms 304 KB Partially correct
14 Correct 7 ms 312 KB Output is correct
15 Correct 3 ms 212 KB Output is correct
16 Correct 15 ms 340 KB Output is correct
17 Correct 7 ms 212 KB Output is correct
18 Partially correct 15 ms 308 KB Partially correct
19 Partially correct 18 ms 212 KB Partially correct
20 Correct 16 ms 308 KB Output is correct