-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path387326_C.cpp
More file actions
36 lines (31 loc) · 853 Bytes
/
387326_C.cpp
File metadata and controls
36 lines (31 loc) · 853 Bytes
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
int N, M; cin >> N >> M;
string str[N];
for (int i = 0; i < N; i++) cin >> str[i];
bool found = false;
bool removed[M]; memset(removed, 0, sizeof removed);
for (int i = 0; i < M; i++) {
for (int j = 0; j < N-1; j++) {
if (str[j][i] > str[j+1][i]) {
bool skip = false;
for (int k = 0; k < i; k++) {
if (removed[k]) continue;
skip |= str[j][k] < str[j+1][k];
}
if (skip) continue;
removed[i] = true;
}
}
}
int result = 0;
for (int i = 0; i < M; i++) result += removed[i];
cout << result;
}
int main()
{
solve();
return 0;
}