-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8907.cpp
60 lines (56 loc) · 1.15 KB
/
8907.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
#include <iostream>
#include <string.h>
using namespace std;
#define Max 1000
namespace FIO {
const size_t BUFFER_SIZE = 524288;
char buffer[BUFFER_SIZE];
char* ptr = buffer + BUFFER_SIZE;
inline char readByte() {
if (ptr == buffer + BUFFER_SIZE) {
fread(buffer, 1, BUFFER_SIZE, stdin);
ptr = buffer;
}
return *(ptr++);
}
unsigned int readUnsigned() {
unsigned int ret = 0;
char c = readByte();
while (!('0' <= c && c <= '9')) {
c = readByte();
}
while ('0' <= c && c <= '9') {
ret = ret * 10 + (c - '0');
c = readByte();
}
return ret;
}
};
int tot, T, N, cnt[Max][2];
void init() {
memset(cnt, 0, sizeof(cnt));
tot = 0;
}
int main() {
T = FIO::readUnsigned();
while(T--) {
N = FIO::readUnsigned();
for (int i = 0; i < N; ++i) {
cnt[i][0] = cnt[i][1] = 0;
}
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
int v = FIO::readUnsigned();
cnt[i][v] += 1;
cnt[j][v] += 1;
}
}
int sum = 0;
for (int i = 0; i < N; i++)
sum += cnt[i][0] * cnt[i][1];
tot = N * (N - 1)*(N - 2);
tot /= 6; sum /= 2;
printf("%d\n", tot- sum);
}
return 0;
}