답안 #992076

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
992076 2024-06-03T20:33:03 Z parlimoos Amusement Park (CEOI19_amusementpark) C++14
7 / 100
1 ms 6492 KB
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define cl clear
#define bg begin
#define lb lower_bound
#define ub upper_bound
#define arr(x) array<int , x>
#define endl '\n'

const int MOD = 998244353;

int n , m;
int g[18][18] , inf[18];
int dp[18][(1 << 18)][2];

int Sum(int a , int b){
    int res = a + b;
    if(res > MOD) return res - MOD;
    if(res < 0) return res + MOD;
    return res;
}
void Add(int &a , int b){
    a += b;
    if(a > MOD) a -= MOD;
    if(a < 0) a += MOD;
}
int Mul(int a , int b){
    return (1ll * a * b) % MOD;
}
void f(){
    for(int b = 0 ; b < n ; b++) dp[b][0][0] = 1;
    for(int msk = 1 ; msk < (1 << n) ; msk++){
        for(int v = 0 ; v < n ; v++){
            if(!((msk >> v) & 1)) continue;
            inf[v] = 0;
            for(int u = 0 ; u < n ; u++) if(((msk >> u) & 1) and g[u][v] == 1) inf[v]++;
        }
        if(msk == (1 << n) - 1){
            for(int v = 0 ; v < n ; v++){
                Add(dp[0][msk][0] , dp[v][msk ^ (1 << v)][0]);
                Add(dp[0][msk][1] , Sum(Mul(inf[v] , dp[v][msk ^ (1 << v)][0]) , dp[v][msk ^ (1 << v)][1])); 
            }
        }else{
            for(int b = 0 ; b < n ; b++){
                if(((msk >> b) & 1)) continue;
                for(int v = 0 ; v < n ; v++){
                    if(!((msk >> v) & 1) or (v <= b and g[v][b] == 0)) continue;
                    // if(msk == 5 and b == 1) cout << v << " " << (msk ^ (1 << v)) << " " << inf[v] << "__\n";
                    Add(dp[b][msk][0] , dp[v][msk ^ (1 << v)][0]);
                    Add(dp[b][msk][1] , Sum(Mul(inf[v] , dp[v][msk ^ (1 << v)][0]) , dp[v][msk ^ (1 << v)][1]));
                }
                // if(msk == 5 and b == 1) cout << dp[b][msk][0] << "||\n";
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int v , u;
        cin >> v >> u;
        v-- , u--;
        g[v][u] = 1 , g[u][v] = -1;
    }
    f();
    cout << dp[0][(1 << n) - 1][1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Incorrect 1 ms 6492 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Incorrect 1 ms 6492 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Incorrect 1 ms 6492 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Incorrect 1 ms 6492 KB Output isn't correct
10 Halted 0 ms 0 KB -