Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int Maxn = 55, Maxm = 105;
- int n, m;
- struct perm {
- int p[Maxn];
- perm() {
- for (int i = 0; i < n; i++) p[i] = i;
- }
- perm(const perm &u) {
- for (int i = 0; i < n; i++) p[i] = u.p[i];
- }
- perm inv(void) {
- perm res;
- for (int i = 0; i < n; i++)
- res.p[p[i]] = i;
- return res;
- }
- } P[Maxm], *B[Maxn][Maxn];
- perm mul(perm a, perm b, int i) {
- perm res;
- for (; i < n; i++)
- res.p[i] = a.p[b.p[i]];
- return res;
- }
- bool vis[Maxn][Maxn];
- queue <pair <int, int> > Qu;
- void sifting(perm sigma) {
- for (int i = 0; i < n; i++) {
- if (B[i][sigma.p[i]] == NULL)
- return B[i][sigma.p[i]] = new perm(sigma), Qu.push(make_pair(i, sigma.p[i]));
- if (sigma.p[i] != i) sigma = mul(B[i][sigma.p[i]] -> inv(), sigma, i);
- }
- }
- const unsigned long long lim = 1e18;
- struct output {
- unsigned long long val[4];
- output() {
- val[0] = val[1] = val[2] = 0, val[3] = 1;
- }
- output operator * (int x) {
- output res = *this;
- for (int i = 0; i <= 3; i++) {
- __int128 tmp = (__int128) res.val[i] * x;
- res.val[i - 1] += tmp / lim, res.val[i] = (long long) (tmp % lim);
- }
- for (int i = 3; i >= 0; i--)
- if (res.val[i] >= lim) res.val[i] -= lim, res.val[i - 1]++;
- return res;
- }
- void print(void) {
- bool flag = false;
- for (int i = 0; i <= 3; i++) {
- if (flag) printf("%018llu", val[i]);
- else if (val[i])
- printf("%llu", val[i]), flag = true;
- }
- }
- } ans;
- int main() {
- scanf("%d%d", &n, &m);
- for (int i = 0; i < m; i++)
- for (int j = 0; j < n; j++)
- scanf("%d", &P[i].p[j]), P[i].p[j]--;
- B[0][0] = new perm();
- for (int i = 1; i < n; i++)
- B[i][i] = B[0][0];
- for (int i = 0; i < m; i++)
- sifting(P[i]);
- while (!Qu.empty()) {
- int x = Qu.front().first, y = Qu.front().second;
- Qu.pop();
- for (int i = 0; i < n; i++)
- for (int j = i + 1; j < n; j++)
- if (B[i][j] != NULL) sifting(mul(*B[i][j], *B[x][y], 0));
- }
- for (int i = 0; i < n; i++) {
- int cnt = 0;
- for (int j = i; j < n; j++)
- if (B[i][j] != NULL) cnt++;
- ans = ans * cnt;
- }
- return ans.print(), 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement