Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define PB push_back
- #define D(X) cout<<" "<<#X": "<<X<<endl;
- #define CL(A,I) (memset(A,I,sizeof(A)))
- #define aa first
- #define bb second
- #define FOR(i, m, n) for (int i(m); i < (int)n; i++)
- #define REP(i, n) FOR(i, 0, n)
- #define F(n) FOR(i, 0, n)
- #define FF(n) FOR(j, 0, n)
- typedef long long ll;
- typedef pair<ll,ll> ii;
- typedef vector<ll> vi;
- typedef vector<ii> vii;
- int n, m, tr[22];
- set<string> vs;
- string cs;
- struct nd {int l, r, v;};
- nd nds[32];
- void dfs(int x) {
- cs += "(";
- if (nds[x].l != -1) dfs(nds[x].l);
- else cs += "[]";
- if (nds[x].r != -1) dfs(nds[x].r);
- else cs += "{}";
- cs += ")";
- }
- int main() {
- scanf("%d%d", &n, &m);
- F(n) {
- FF(m) scanf("%d", &tr[j]);
- nds[0] = {-1, -1, tr[0]};
- cs = "";
- FOR(j, 1, m) {
- int cur = 0;
- while (1) {
- if (nds[cur].v < tr[j]) {
- if (nds[cur].l == -1) {
- nds[j] = {-1, -1, tr[j]};
- nds[cur].l = j;
- break;
- } else {
- cur = nds[cur].l;
- }
- } else {
- if (nds[cur].r == -1) {
- nds[j] = {-1, -1, tr[j]};
- nds[cur].r = j;
- break;
- } else {
- cur = nds[cur].r;
- }
- }
- }
- }
- dfs(0);
- vs.insert(cs);
- }
- printf("%d\n", (int)vs.size());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement