답안 #486337

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486337 2021-11-11T10:17:18 Z XII Amusement Park (CEOI19_amusementpark) C++17
0 / 100
0 ms 204 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "CEOI19_amusementpark"
void Fi(){
    if(fopen(PROB".inp", "r")){
        freopen(PROB".inp", "r", stdin);
        freopen(PROB".out", "w", stdout);
    }
}

const int N = 18;
int n, m;
vector<int> adj[N], radj[N];
const int MOD = 998244353;

int dp[1 << N]; /// number of reverse edge
int f[1 << N]; /// number of state

int main(){
    IOS;
    Fi();
    cin >> n >> m;
    FORU(i, 1, m){
        int u, v; cin >> u >> v;
        --u, --v;
        adj[u].eb(v), radj[v].eb(u);
    }
    f[0] = 1;
    FOR(mask, 0, 1 << n){
        FOR(u, 0, n) if(!(mask & (1 << u))){
            int rev = 0;
            for(int v: adj[u]) if(mask & (1 << v)) ++rev;
            (dp[mask | (1 << u)] += f[mask] * rev + dp[mask]) %= MOD;
            (f[mask | (1 << u)] += f[mask]) %= MOD;
        }
    }
//    FOR(mask, 0, 1 << n){
//        cout << bitset<10>(mask) << "\n";
//        cout << f[mask] << " " << dp[mask] << "\n";
//    }
    cout << dp[(1 << n) - 1];
    return 0;
}

Compilation message

amusementpark.cpp: In function 'void Fi()':
amusementpark.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(PROB".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
amusementpark.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(PROB".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -