QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#242863#7687. Randias Permutation TaskhHap#RE 0ms90388kbC++202.6kb2023-11-07 17:54:452023-11-07 17:54:46

Judging History

你现在查看的是最新测评结果

  • [2023-11-07 17:54:46]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:90388kb
  • [2023-11-07 17:54:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int N = 362880 + 10;
int dp[181][N];
int p[180];
int a[181][181];
int b[180];
int n, m, d[185];
const int mod = 1e9 + 7;
map<string, int> ccc;
map<vector<int>, int> ct;
void dfs(int u, int c[])
{
    if (u == m)
    {
        if (!c[1])
            return;
        vector<int> p;
        for (int i = 1; i <= n; i++)
        {
            //   cout << c[i] << " ";
            p.push_back(c[i]);
        }
        //  cout << endl;
        ct[p] = 1;
        return;
    }
    int tmp[24];
    for (int i = 1; i <= n; i++)
        tmp[i] = c[i];
    dfs(u + 1, tmp);
    if (tmp[1])
    {
        for (int i = 1; i <= n; i++)
        {
            d[i] = tmp[a[u + 1][i]];
        }
        dfs(u + 1, d);
    }
    else
        dfs(u + 1, a[u + 1]);
}

void solve()
{
    cin >> n >> m;
    int ans = 0;
    for (int i = 1; i <= m; i++)
    {
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
    }
    for (int i = 1; i <= n; i++)
        p[i] = i;

    if (m > 20)
    {
        map<int, int> mp;
        map<string, int> val;
        int r = 0;
        do
        {
            r++;
            string tmp;
            for (int i = 1; i <= n; i++)
                tmp += '0' + p[i];
            val[tmp] = r;
        } while (next_permutation(p + 1, p + 1 + n));

        for (int i = 1; i <= m; i++)
        {
            int rr = 0;
            for (int j = 1; j <= n; j++)
                p[j] = j;
            int r = 0;
            do
            {
                r++;
                if (!dp[i - 1][r])
                    continue;
                dp[i][r] = 1;
                string tmp;
                for (int j = 1; j <= n; j++)
                {
                    b[j] = a[i][p[j]];
                    tmp += '0' + b[j];
                }
                dp[i][val[tmp]] = 1;
            } while (next_permutation(p + 1, p + 1 + n));
            string tmp;
            for (int j = 1; j <= n; j++)
                tmp += '0' + a[i][j];
            dp[i][val[tmp]] = 1;
            // for(int j=0;j<N;j++) rr+=dp[i][j];
            // cout<<i<<' '<<rr<<endl;
        }
        for (int i = 0; i < N; i++)
            ans += dp[m][i];
        cout << ans % mod;
    }
    else
    {
        dfs(0, d);
        cout << ct.size() << "\n";
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

input:

5 4
1 2 3 4 5
5 1 3 4 2
3 4 1 5 2
5 2 4 1 3

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

2 1
2 1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 90388kb

input:

1 180
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: -100
Runtime Error

input:

180 1
52 71 167 89 165 102 119 125 9 128 180 24 48 172 108 22 164 28 159 111 30 91 67 51 136 97 126 133 177 65 115 157 114 11 171 178 23 127 163 103 99 18 56 94 176 77 44 1 124 74 61 87 4 40 63 92 169 84 146 6 88 55 152 49 10 90 43 174 70 50 69 154 73 147 110 20 82 59 112 12 64 143 16 138 5 170 155 ...

output:


result: