Submission #651401

# Submission time Handle Problem Language Result Execution time Memory
651401 2022-10-18T17:00:07 Z BidoTeima Izbori (COCI17_izbori) C++17
0 / 80
3000 ms 212 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]];
        }
        reverse(a[i].begin(),a[i].end());
    }
    int winner = -1;
    for(int i = 1; i <= m; i++){
        if(winner == -1 || f[i] > f[winner])
            i = winner;
    }
    cout<<winner<<'\n';
    bool vis[m+1]={0};
    int ans = 0;
    while(winner != k){
        vis[winner]=1;
        for(int i = 0; i < n; i++){
            while(vis[a[i].back()]){
                --f[a[i].back()];
                a[i].pop_back();
                ++f[a[i].back()];
            }
        }
        for(int i = 1; i <= m; i++){
            if(winner == -1 || f[i] > f[winner])
                i = winner;
        }
        ++ans;
    }
    cout<<ans<<'\n';
}

Compilation message

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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
izbori.cpp: In function 'int main()':
izbori.cpp:59:19: warning: array subscript -1 is below array bounds of 'bool [(<anonymous> + 1)]' [-Warray-bounds]
   59 |         vis[winner]=1;
      |         ~~~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Execution timed out 3073 ms 212 KB Time limit exceeded
2 Execution timed out 3069 ms 212 KB Time limit exceeded
3 Execution timed out 3050 ms 212 KB Time limit exceeded
4 Execution timed out 3068 ms 212 KB Time limit exceeded
5 Execution timed out 3077 ms 212 KB Time limit exceeded
6 Execution timed out 3060 ms 212 KB Time limit exceeded
7 Execution timed out 3095 ms 212 KB Time limit exceeded
8 Execution timed out 3096 ms 212 KB Time limit exceeded
9 Execution timed out 3071 ms 212 KB Time limit exceeded
10 Execution timed out 3050 ms 212 KB Time limit exceeded
11 Execution timed out 3064 ms 212 KB Time limit exceeded
12 Execution timed out 3056 ms 212 KB Time limit exceeded
13 Execution timed out 3059 ms 212 KB Time limit exceeded
14 Execution timed out 3064 ms 212 KB Time limit exceeded
15 Execution timed out 3067 ms 212 KB Time limit exceeded
16 Execution timed out 3061 ms 212 KB Time limit exceeded
17 Execution timed out 3066 ms 212 KB Time limit exceeded
18 Execution timed out 3056 ms 212 KB Time limit exceeded
19 Execution timed out 3072 ms 212 KB Time limit exceeded
20 Execution timed out 3050 ms 212 KB Time limit exceeded