Submission #666418

# Submission time Handle Problem Language Result Execution time Memory
666418 2022-11-28T15:12:27 Z finn__ Amusement Park (CEOI19_amusementpark) C++17
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

#define MOD 998244353

int main()
{
    size_t n, m;
    cin >> n >> m;

    vector<vector<bool>> g(n, vector<bool>(n, 0));
    for (size_t i = 0; i < m; i++)
    {
        unsigned u, v;
        cin >> u >> v;
        g[u - 1][v - 1] = 1;
    }

    vector<uint64_t> dp(1 << n, 0), nways(1 << n, 0);
    nways[0] = 1;

    for (unsigned i = 0; i < 1 << n; i++)
    {
        for (unsigned j = 0; j < n; j++)
        {
            if (!(i & (1 << j)))
            {
                uint64_t c = 0;
                for (unsigned k = 0; k < n; k++)
                    c += (i & (1 << k)) && g[k][j];

                dp[i ^ (1 << j)] = (dp[i ^ (1 << j)] + dp[i] + c * nways[i]) % MOD;
                nways[i ^ (1 << j)] = (nways[i ^ (1 << j)] + nways[i]) % MOD;
            }
        }
    }

    cout << dp[(1 << n) - 1] << '\n';
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:22:28: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   22 |     for (unsigned i = 0; i < 1 << n; i++)
      |                          ~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 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 0 ms 212 KB Output is correct
3 Incorrect 0 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 0 ms 212 KB Output is correct
3 Incorrect 0 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 0 ms 212 KB Output is correct
3 Incorrect 0 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 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -