답안 #1088029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088029 2024-09-13T18:09:01 Z vjudge1 Izbori (COCI17_izbori) C++17
44 / 80
1 ms 460 KB
#include <bits/stdc++.h>
#include <fstream>
using namespace std;

#define int long long
#define endl '\n'
const int mxn = 501;
const int mod = 1e8;
// int dx[] = {0 , 0 , 1 , -1};
// int dy[] = {1 , -1 , 0 , 0};
//DFS
//----------------------------------
// vector<int> adj[mxn];
// int n , m;
// bool vis[mxn];
// int P[mxn];
// int rem[mxn];
// void dfs(int i){
//     vis[i] = 1;
//     for(auto j : adj[i]){
//         if(!vis[j]){
//             P[j] = i;
//             dfs(j);
//         }
//     }
//     return;
// }
//----------------------------------
//Seg-Tree
//----------------------------------
// int Tree[1 << (int)(ceil(log2(mxn))) + 1];
// int N = 1 << (int)(ceil(log2(mxn)));
// int l ,r;
// int Search(int i , int lr , int rr){
//     if(lr >= l and rr <= r){
//         return Tree[i];
//     }
//     if(lr > r or rr < l) return -1;
//     return max(Search(i * 2 , lr , (lr + rr) / 2) , Search(i * 2 + 1 , (lr + rr) / 2 + 1 , rr));
// }
// void update(int i){
//     while(i /= 2){
//         Tree[i] = max(Tree[i * 2] , Tree[i * 2 + 1]);
//     }
//     return;
// }
//----------------------------------
//comp
//----------------------------------
// map<int , int>mp;
// map<int , int>pm;
// void comp(set<int>s)
// {
//     int idx = 0;
//     for(auto i : s){
//         mp[i] = idx;
//         pm[idx] = i;
//         idx ++;
//     }
// }
//----------------------------------
signed main() {
  cin.tie(0) -> sync_with_stdio(0);
  int n , m , k;
  cin >> n >> m >> k;
  vector<int>vec[n];
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < m; j ++){
      int x;
      cin >> x;
      vec[i].push_back(x);
    }
  }
  bool used[m + 5] = {};
  int cnt[m + 5] = {};
  int mx = vec[0][0];
  for(int i = 0 ; i < n ; i++){
    cnt[vec[i][0]] ++;
    if(cnt[vec[i][0]] > cnt[mx] || (cnt[mx] == cnt[vec[i][0]] and vec[i][0] < mx)) mx = vec[i][0];
  }
  cout << mx << endl;
  int sol = 0;
  for(auto &i : cnt) i = 0;
  while(true){
    int mx = vec[0][0];
    for(int i = 0 ; i < n ; i++){
      int cur = vec[i][0];
      int j = 0;
      bool flag = 0;
      while(used[cur]){
        if(vec[i].size() < j + 1) flag = 1;;
        j ++;
        cur = vec[i][j];
      }
      if(flag) continue;
      cnt[cur] ++;
      if(cnt[cur] > cnt[mx] || (cnt[mx] == cnt[cur] and cur < mx)) mx = cur;
    }
    if(mx != k){
      sol ++;
      used[mx] = 1;
    }
    else return cout << sol , 0;
  }
}

Compilation message

izbori.cpp: In function 'int main()':
izbori.cpp:91:26: 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]
   91 |         if(vec[i].size() < j + 1) flag = 1;;
      |            ~~~~~~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 348 KB Partially correct
2 Partially correct 1 ms 348 KB Partially correct
3 Partially correct 1 ms 348 KB Partially correct
4 Partially correct 0 ms 344 KB Partially correct
5 Partially correct 0 ms 348 KB Partially correct
6 Partially correct 1 ms 348 KB Partially correct
7 Partially correct 1 ms 348 KB Partially correct
8 Partially correct 0 ms 348 KB Partially correct
9 Partially correct 0 ms 348 KB Partially correct
10 Partially correct 0 ms 348 KB Partially correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Partially correct 0 ms 348 KB Partially correct
14 Partially correct 1 ms 348 KB Partially correct
15 Partially correct 1 ms 348 KB Partially correct
16 Partially correct 0 ms 348 KB Partially correct
17 Partially correct 0 ms 348 KB Partially correct
18 Partially correct 1 ms 348 KB Partially correct
19 Partially correct 1 ms 348 KB Partially correct
20 Partially correct 0 ms 460 KB Partially correct