Submission #779320

# Submission time Handle Problem Language Result Execution time Memory
779320 2023-07-11T10:25:54 Z nonono Amusement Park (CEOI19_amusementpark) C++14
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int mod = 998244353;
const int N = 18;
int n, m;
int slide[N][N];
int Use[N][N];
long long dp1[1 << N], dp2[1 << N];

signed main(){
#define taskname ""

    if(fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    cin.tie(0)->sync_with_stdio(0);
    
    cin >> n >> m;
    
    for(int i = 1; i <= m; i ++){
        int a, b;
        cin >> a >> b;
        a -- ; b -- ;
        
        slide[a][b] = 0;
        slide[b][a] = 1;
        
        Use[a][b] = 1;
        Use[b][a] = 1;
    }
    
    for(int i = 0; i < n; i ++) dp1[1 << i] = 1;
    
    for(int mask = 1; mask < (1 << n); mask ++){
        
        for(int x = (1 << n) - 1 - mask; x > 0; x ^= x & (- x)){
            int i = __builtin_ctz(x & (- x));
            
            bool check = false;
            for(int y = mask; y > 0; y ^= y & (- y)){
                int j = __builtin_ctz(y & (- y));
                check = (check || Use[j][i]);    
            }
            
            if(check){
                for(int y = mask; y > 0; y ^= y & (- y)){
                    int j = __builtin_ctz(y & (- y));
                    (dp2[mask ^ (1 << i)] += dp1[mask] * slide[j][i]) %= mod;
                }
                
                (dp2[mask ^ (1 << i)] += dp2[mask]) %= mod;
                (dp1[mask ^ (1 << i)] += dp1[mask]) %= mod;
            }
        }
    }
    
    cout << dp2[(1 << n) - 1] << "\n";
    return 0;
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
amusementpark.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -