This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 18
#define mod 998244353
lli n,m,total;
lli pot[47],orden[MAX+2];
pair<lli,lli> slides[47];
unordered_map<lli, lli> mapa;
void checa() {
    lli num = 0;
    lli rparcial = 0;
    rep(i,1,m) {
        if (orden[slides[i].first] > orden[slides[i].second]) {
            num += pot[i];
            rparcial++;
        }
    }
    if (mapa.find(num) == mapa.end()) {
        mapa[num] = 1;
        total += rparcial;
        if (total >= mod) total -= mod;
    }
}
void genera(lli k) {
    rep(i,1,n) {
        if (orden[i] > 0) continue;
        orden[i] = k;
        if (k == m) checa();
        else genera(k+1);
        orden[i] = 0;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    rep(i,1,m) cin >> slides[i].first >> slides[i].second;
    pot[1] = 1;
    rep(i,2,m) pot[i] = pot[i-1]*2;
    genera(1);
    cout << total;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |