-
Notifications
You must be signed in to change notification settings - Fork 3
/
ausoara.cpp
49 lines (44 loc) · 969 Bytes
/
ausoara.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in ("ausoara.in");
ofstream out ("ausoara.out");
vector<vector<unsigned>> data;
vector<unsigned> ind;
vector<unsigned> sol;
bool cmp(const vector<unsigned> &a,const vector<unsigned> &b) {
return a.size()<b.size();
}
int main() {
int n;
in >> n;
data.resize(n);
ind.resize(n);
for(int i = 0; i < n; ++i) {
int sz;
in >> sz;
data[i].resize(sz);
for(int j = 0; j < sz; ++j) {
in >> data[i][j];
}
}
sort(data.begin(), data.end(),cmp);
for(ind[0] = 0; ind[0] < data[0].size(); ++ind[0]) {
int val = data[0][ind[0]];
bool isEq = true;
for(int j = 1; j < n; j++) {
for(;ind[j]<data[j].size()&&data[j][ind[j]]<val;ind[j]++);
if(data[j][ind[j]]!=val) {
isEq = false;
}
}
if(isEq){
sol.push_back(val);
for(int i = 1; i < n; ++i)ind[i]++;
}
}
out << sol.size() << ' ';
for(int i = 0; i < sol.size(); ++i)
out << sol[i] << ' ';
}