// 愚直解 #include #define MAX_N 100000 #define MAX_K 10 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma warning(disable: 4996) int main(void) { int N, K; scanf("%d", &N); scanf("%d", &K); char s[MAX_N][MAX_K]; for (int i = 0; i < N; ++i) { scanf("%s", s[i]); } int local_max[MAX_N]; for (int i = 0; i < N; ++i) { local_max[i] = 1; } for (int i = 0; i < N - 1; ++i) { for (int j = i + 1; j < N; ++j) { int flag = 1; for (int k = 0; k < K; ++k) { if (s[i][k] <= s[j][k]) { continue; } flag = 0; break; } if (flag == 1) { local_max[j] = 0; continue; } flag = 1; for (int k = 0; k < K; ++k) { if (s[i][k] >= s[j][k]) { continue; } flag = 0; break; } if (flag == 1) { local_max[i] = 0; continue; } } } int ans = N; for (int i = 0; i < N; ++i) { ans -= local_max[i]; } printf("%d\n", ans); return 0; }