-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chef_and_Ants.cpp
62 lines (45 loc) · 1.45 KB
/
Chef_and_Ants.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
50
51
52
53
54
55
56
57
58
59
60
61
62
// https://www.codechef.com/problems/ANTSCHEF
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
class Line_info {
public:
lli l;
lli *X;
lli pos, neg, linecolO;
};
int main() {
int t; cin >> t;
for(int k = 0; k < t; k++) {
lli no; cin >> no;
map<lli, lli> map1_line;
map<lli, lli> Whole_map;
map<lli, lli>::iterator iterate;
lli ALL_collision_WO = 0, T_col_AT_O = 0;
Line_info Lines[no];
for (int i = 0; i < no ; i++) {
Lines[i].pos = 0;
Lines[i].neg = 0;
Lines[i].linecolO = 0;
cin >> Lines[i].l;
Lines[i].X = new lli[Lines[i].l];
for (lli j = 0; j < Lines[i].l ; j++ ) {
cin >> Lines[i].X[j];
if (Lines[i].X[j] < 0) Lines[i].neg++;
else Lines[i].pos++;
map1_line[abs(Lines[i].X[j])]++;
Whole_map[abs(Lines[i].X[j])]++;
}
for (iterate=map1_line.begin(); iterate!= map1_line.end(); iterate++) {
if (iterate->second > 1) Lines[i].linecolO++;
}
ALL_collision_WO += Lines[i].pos*Lines[i].neg - Lines[i].linecolO;
map1_line.clear();
}
for ( iterate=Whole_map.begin(); iterate!= Whole_map.end(); iterate++) {
if (iterate->second > 1) T_col_AT_O++;
}
cout << T_col_AT_O + ALL_collision_WO << endl;
}
return 0;
}