-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe1252 v2 bools.c
41 lines (36 loc) · 1.02 KB
/
e1252 v2 bools.c
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
// Swapped to using bools but for some reason it's slower than ints hm
// Memory is also worse oddly
int oddCells(int m, int n, int** indices, int indicesSize, int* indicesColSize) {
bool** refren = (bool**) malloc(sizeof(bool*) * m);
for (int i = 0; i < m; i++) {
refren[i] = (bool*) malloc(sizeof(bool) * n);
for (int j = 0; j < n; j++) {
refren[i][j] = false;
}
}
for (int i = 0; i < indicesSize; i++) {
// rows
int row = indices[i][0];
for (int j = 0; j < n; j++) {
refren[row][j] = !refren[row][j];
}
// cols
int col = indices[i][1];
for (int j = 0; j < m; j++) {
refren[j][col] = !refren[j][col];
}
}
int output = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (refren[i][j]) {
output++;
}
}
}
for (int i = 0; i < m; i++) {
free(refren[i]);
}
free(refren);
return output;
}