이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |