답안 #1087408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087408 2024-09-12T15:56:58 Z vjudge1 Izbori (COCI17_izbori) C++17
44 / 80
1 ms 348 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;
  while(true){
    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];
    }
    if(mx != k){
      sol ++;
      for(int i = 0 ; i < n; i++){
        for(int j = 0 ; j < vec[i].size() ; j++){
          if(vec[i][j] == mx){
            vec[i].erase(vec[i].begin() + j);
            break;
          }
        }
      }
    }
    else return cout << sol , 0;
  }
}

Compilation message

izbori.cpp: In function 'int main()':
izbori.cpp:92:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |         for(int j = 0 ; j < vec[i].size() ; j++){
      |                         ~~^~~~~~~~~~~~~~~
izbori.cpp:74:8: warning: unused variable 'used' [-Wunused-variable]
   74 |   bool used[m + 5] = {};
      |        ^~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 344 KB Partially correct
2 Partially correct 0 ms 348 KB Partially correct
3 Partially correct 1 ms 348 KB Partially correct
4 Partially correct 0 ms 348 KB Partially correct
5 Partially correct 0 ms 348 KB Partially correct
6 Partially correct 0 ms 348 KB Partially correct
7 Partially correct 0 ms 348 KB Partially correct
8 Partially correct 0 ms 348 KB Partially correct
9 Partially correct 0 ms 344 KB Partially correct
10 Partially correct 1 ms 344 KB Partially correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Partially correct 0 ms 348 KB Partially correct
14 Partially correct 0 ms 348 KB Partially correct
15 Partially correct 1 ms 348 KB Partially correct
16 Partially correct 1 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 344 KB Partially correct