Submission #599937

# Submission time Handle Problem Language Result Execution time Memory
599937 2022-07-20T09:47:19 Z M_W Amusement Park (CEOI19_amusementpark) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
int dp[210002][257]; // subset, cost
vector<int> adj[19], rev[19];
vector<int> ss[19];
bool adjm[19][19];

int main(){
    int N, M;
    scanf("%d %d", &N, &M);
    for(int i = 0, u, v; i < M; i++){
        scanf("%d %d", &u, &v);
        adj[u].push_back(v);
        rev[v].push_back(u);

        adjm[u][v] = adjm[v][u] = true;
    }

    for(int i = 0; i < 1 << N; i++){
        int cnt = 0;
        for(int j = 0; j < N; j++){
            if(i & 1 << j) cnt++;
        }
        ss[cnt].push_back(i);
    }
    
    for(int i = 0; i < N; i++) dp[1 << i][0] = 1;
    for(int i = 1; i <= N; i++){
        // subset
        for(auto x : ss[i]){
            // for(int i = 0; i <= M; i++){
            //     printf(">> %d %d: %d\n", x, i, dp[x][i]);
            // }
            for(int bit = 0; bit < N; bit++){
                if(!(x & 1 << bit)){
                    int c = 0; bool ok = false;
                    for(auto u : rev[bit + 1]) if(x & (1 << (u - 1))) ok = true;
                    for(auto u : adj[bit + 1]){
                        if(x & (1 << (u - 1))){
                            c++; ok = true;
                        }
                    }
                    if(ok){
                        for(int i = 0; i <= M; i++){
                            dp[x | (1 << bit)][i + c] += dp[x][i];
                        }
                    } 
                }
            }
        }
    }
    long long ans = 0, md = 998244353;
    for(int i = 0; i <= M; i++){
        ans = (ans + ((i * dp[(1 << N) - 1][i]) % md)) % md;
    }
    printf("%lld\n", ans);
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~
amusementpark.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -