# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1088520 |
2024-09-14T14:44:43 Z |
vjudge1 |
Izbori (COCI17_izbori) |
C++17 |
|
76 ms |
65536 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 ++;
// }
// }
//----------------------------------
int n , m , k;
vector<int>a;
set<int>glo;
vector<set<int>>subsets;
void rec(int i){
if(i == a.size()) return;
glo.insert(a[i]);
subsets.push_back(glo);
rec(i + 1);
glo.erase(a[i]);
rec(i + 1);
return;
}
int solve(vector<vector<int>>vec){
int mx = -1;
int cnt[m + 5] = {};
for(int i = 0 ; i < n; i++){
if(vec[i].empty()) continue;
if(mx == -1) mx = vec[i][0];
cnt[vec[i][0]] ++;
if(cnt[vec[i][0]] > cnt[mx] || (cnt[vec[i][0]] == cnt[mx] and vec[i][0] < mx)) mx = vec[i][0];
}
if(m - vec[0].size() == 0){
cout << mx << endl;
}
if(mx == k) return m - vec[0].size();
else return 1e9;
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m >> k;
set<int>mt;
subsets.push_back(mt);
vector<int>v[n];
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < m ; j++){
int x;
cin >> x;
if(x != k) a.push_back(x);
v[i].push_back(x);
}
}
rec(0);
int mn = 1e9;
for(int i = 0 ; i < subsets.size() ; i++){
vector<vector<int>>sol;
for(int k = 0 ; k < n ; k++){
vector<int>p;
for(int j = 0 ; j < m ; j++){
if(subsets[i].find(v[k][j]) == subsets[i].end()){
p.push_back(v[k][j]);
}
}
sol.push_back(p);
}
mn = min(mn , solve(sol));
}
cout << mn << endl;
}
Compilation message
izbori.cpp: In function 'void rec(int)':
izbori.cpp:67:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | if(i == a.size()) return;
| ~~^~~~~~~~~~~
izbori.cpp: In function 'int main()':
izbori.cpp:106:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for(int i = 0 ; i < subsets.size() ; i++){
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
63 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Runtime error |
66 ms |
65536 KB |
Execution killed with signal 9 |
3 |
Runtime error |
69 ms |
65536 KB |
Execution killed with signal 9 |
4 |
Runtime error |
68 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Runtime error |
69 ms |
65536 KB |
Execution killed with signal 9 |
6 |
Runtime error |
66 ms |
65536 KB |
Execution killed with signal 9 |
7 |
Runtime error |
76 ms |
65536 KB |
Execution killed with signal 9 |
8 |
Runtime error |
67 ms |
65536 KB |
Execution killed with signal 9 |
9 |
Runtime error |
69 ms |
65536 KB |
Execution killed with signal 9 |
10 |
Runtime error |
66 ms |
65536 KB |
Execution killed with signal 9 |
11 |
Runtime error |
72 ms |
65536 KB |
Execution killed with signal 9 |
12 |
Runtime error |
66 ms |
65536 KB |
Execution killed with signal 9 |
13 |
Runtime error |
63 ms |
65536 KB |
Execution killed with signal 9 |
14 |
Runtime error |
71 ms |
65536 KB |
Execution killed with signal 9 |
15 |
Runtime error |
68 ms |
65536 KB |
Execution killed with signal 9 |
16 |
Runtime error |
63 ms |
65536 KB |
Execution killed with signal 9 |
17 |
Runtime error |
69 ms |
65536 KB |
Execution killed with signal 9 |
18 |
Runtime error |
67 ms |
65536 KB |
Execution killed with signal 9 |
19 |
Runtime error |
66 ms |
65536 KB |
Execution killed with signal 9 |
20 |
Runtime error |
71 ms |
65536 KB |
Execution killed with signal 9 |