// 愚直解 #include #include #define rep(i, l, r) for(int i = (l); i < (r); ++i) #define MAX_N 200000 #define MAX_K 8 #define MAX_DIFF 33 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma warning(disable: 4996) typedef struct _cell { int value; struct _cell* next; struct _cell* prev; }CELL; CELL* head[MAX_DIFF] = { NULL }; inline void insert_cell(int d, int v) { CELL* new_cell = (CELL*)malloc(sizeof(CELL)); new_cell->value = v; new_cell->next = head[d]; new_cell->prev = NULL; head[d] = new_cell; if (head[d]->next != NULL) { head[d]->next->prev = head[d]; } } inline CELL* delete_cell(int d, CELL* p) { if (p == NULL) { return NULL; } CELL* pp = p->prev; if (pp != NULL) { pp->next = p->next; } else { head[d] = p->next; } CELL* np = p->next; if (np != NULL) { np->prev = p->prev; } free(p); return np; } int main(void) { int N, K; scanf("%d", &N); scanf("%d", &K); char s[MAX_N][MAX_K + 1]; rep(i, 0, N) { scanf("%s", s[i]); } rep(i, 0, N) { int diff = 0; rep(j, 0, K) { int d = abs(s[i][j] - '0'); diff += d; if (d > s[i][K]) { s[i][K] = d; } } insert_cell(diff, i); } int ans = 0; for (int i = MAX_DIFF - 1; i > 0; --i) { CELL* p1 = head[i]; while (p1 != NULL) { rep(j, 0, i) { CELL* p2 = head[j]; while (p2 != NULL) { if (s[p1->value][K] < s[p2->value][K]) { p2 = p2->next; continue; } int flag = 1; rep(k, 0, K) { if (s[p1->value][k] >= s[p2->value][k]) { continue; } flag = 0; break; } if (flag) { ++ans; p2 = delete_cell(j, p2); } else { p2 = p2->next; } } } p1 = p1->next; } } printf("%d\n", ans); return 0; }