-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF- 496C.cpp
72 lines (63 loc) · 1.5 KB
/
CF- 496C.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
61
62
63
64
65
66
67
68
69
70
71
72
// Rodrigo Farias de Macêdo
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define EACHR(it,a) for(__typeof(a.rbegin()) it = a.rbegin(); it != a.rend(); ++it)
#define SZ(S) ((int) ((S).size()))
#define DEBUG(x) { cout << #x << " = " << x << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl; }
typedef vector<int> vi;
bitset<100> del;
int n, m;
int val[100][100];
void solve(int col, vector<int> idx){
if(col >= m) return;
vi prox[200];
bool flag = true;
//DEBUG(col);
//PR0(idx, idx.size());
int anterior = val[idx[0]][col];
prox[val[idx[0]][col]].push_back(idx[0]);
FOR(i, 1, idx.size()-1){
if(val[idx[i]][col] < anterior){
del[col] = 1;
solve(col+1, idx);
flag = false;
}
prox[val[idx[i]][col]].push_back(idx[i]);
anterior = val[idx[i]][col];
}
if(flag){
REP(i, 200){
if(prox[i].size() > 0){
solve(col+1, prox[i]);
}
}
}
}
int main(){
scanf("%d %d", &n, &m);
string c;
REP(i, n){
cin >> c;
REP(j, m){
val[i][j] = c[j];
}
}
vi idx;
REP(i, n){
idx.push_back(i);
}
solve(0, idx);
int res = 0;
REP(i, m){
if(del[i] == 1) res++;
}
cout << res << endl;
return 0;
}