QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#245606#7687. Randias Permutation TaskUNos_maricones#TL 1ms3728kbC++142.0kb2023-11-10 05:43:232023-11-10 05:43:23

Judging History

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

  • [2023-11-10 05:43:23]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3728kb
  • [2023-11-10 05:43:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back

typedef long long ll;
typedef pair <int,int> pii;

const int N = 185;
const int MAX_FACT = 362885;

int n, m;
vector <int> perm[N];
unordered_map <string, int> mp;
set <int> s;
string aux;

bool vis[MAX_FACT][N];
void get_cant (int id_perm, int ind, string &str ) {
    if ( vis[id_perm][ind] ) return;
    s.insert ( id_perm );
    if ( ind < 0 ) return;
    get_cant ( id_perm, ind-1, str );
    for ( int i = 0; i < n; ++i )
        aux[i] = perm[ind][str[i]-'1']+'0';
    id_perm = mp[aux];
    str = aux;
    get_cant ( id_perm, ind-1, str );
    return;
}

int checkPerm () {
    string bas_perm = "";
    for ( int i = 1; i <= n; ++i )
        bas_perm.pb ( i + '0' );
    int it = 0;
    do {
        mp[bas_perm] = it++;
    } while ( next_permutation ( bas_perm.begin(), bas_perm.end() ) );
    get_cant ( it, m-1, bas_perm );
    return s.size() - 1;
}

unordered_set <string> us;
int checkSubsets () {
    vector <int> curr_p ( n );
    for ( int mask = 1; mask < (1 << m); ++mask ) {
        for ( int i = 0; i < n; ++i )
            curr_p[i] = i+1;
        for ( int j = m-1; j >= 0; --j ) {
            if ( !((mask>>j)&1) ) continue;
            for ( int i = 0; i < n; ++i )
                curr_p[i] = perm[j][curr_p[i]-1];
        }
        string curr_str = "";
        for ( int i = 0; i < n; ++i )
            curr_str += curr_p[i] + '0';
        us.insert ( curr_str );
    }
    return us.size();
}

int main () {
        
    #ifndef LOCAL
    #endif

    scanf ( "%d%d", &n, &m );
    aux = string ( n, ' ' );
    for ( int i = 0; i < m; ++i ) {
        for ( int h = 0; h < n; ++h ) {
            int curr;
            scanf ( "%d", &curr );
            perm[i].pb ( curr );
        }
    }

    int res;
    if ( n <= 9 ) {
        res = checkPerm ();
    } else {
        res = checkSubsets ();
    }
    printf ( "%d\n", res );

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3684kb

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: 3728kb

input:

2 1
2 1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: -100
Time Limit Exceeded

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:


result: