답안 #928343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
928343 2024-02-16T08:45:41 Z vjudge1 Amusement Park (CEOI19_amusementpark) C++17
0 / 100
0 ms 348 KB
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #include <x86intrin.h>

#include <bits/stdc++.h>
#include <chrono>
#include <random>

// @author: Vlapos

namespace operators
{
    template <typename T1, typename T2>
    std::istream &operator>>(std::istream &in, std::pair<T1, T2> &x)
    {
        in >> x.first >> x.second;
        return in;
    }

    template <typename T1, typename T2>
    std::ostream &operator<<(std::ostream &out, std::pair<T1, T2> x)
    {
        out << x.first << " " << x.second;
        return out;
    }

    template <typename T1>
    std::istream &operator>>(std::istream &in, std::vector<T1> &x)
    {
        for (auto &i : x)
            in >> i;
        return in;
    }

    template <typename T1>
    std::ostream &operator<<(std::ostream &out, std::vector<T1> &x)
    {
        for (auto &i : x)
            out << i << " ";
        return out;
    }

    template <typename T1>
    std::ostream &operator<<(std::ostream &out, std::set<T1> &x)
    {
        for (auto &i : x)
            out << i << " ";
        return out;
    }
}

// name spaces
using namespace std;
using namespace operators;
// end of name spaces

// defines
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define uint unsigned int
#define all(vc) vc.begin(), vc.end()
// end of defines

// usefull stuff

void boost()
{
    ios_base ::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

inline int getbit(int &x, int &bt) { return (x >> bt) & 1; }

const int dx4[4] = {-1, 0, 0, 1};
const int dy4[4] = {0, -1, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy8[8] = {-1, -0, 1, -1, 1, -1, 0, 1};

const ll INF = (1e18) + 500;
const int BIG = (1e9) * 2 + 100;
const int MAXN = (1e5) + 5;
const int MOD7 = (1e9) + 7;
const int MOD9 = (1e9) + 9;
const uint MODFFT = 998244353;

#define int ll

vector<ll> fact;

void initfact(ll sz, ll mod)
{
    fact.resize(sz);
    fact[0] = 1;
    for (int i = 1; i < sz; i++)
    {
        fact[i] = (fact[i - 1] * i);
        fact[i] %= mod;
    }
}
ll binpow(ll val, ll deg, ll mod)
{
    if (!deg)
        return 1 % mod;
    if (deg & 1)
        return binpow(val, deg - 1, mod) * val % mod;
    ll res = binpow(val, deg >> 1, mod);
    return (res * res) % mod;
}
ll invert(ll n, int mod)
{
    return binpow(n, mod - 2, mod);
}
ll cnk(int n, int k, int mod)
{
    ll res = fact[n];
    ll div = fact[n - k] * fact[k];
    div %= mod;
    div = binpow(div, mod - 2, mod);
    return (res * div) % mod;
}

struct test
{
    vector<vector<int>> graph;
    vector<int> was;
    int n, m;

    bool dfs(int v)
    {
        was[v] = 1;
        for (int i = 0; i < n; ++i)
            if (graph[v][i] and was[i] != 2)
            {
                if (was[i] == 1 or !dfs(i))
                    return false;
            }
        was[v] = 2;
        return true;
    }

    void solve(int testcase)
    {
        boost();

        cin >> n >> m;

        was.resize(n);
        graph.resize(n, vector<int>(n));
        vector<pii> edges;

        for (int i = 0; i < m; ++i)
        {
            int v, tov;
            cin >> v >> tov;
            --v, --tov;
            edges.pb({v, tov});
            graph[v][tov] = 1;
        }

        int res = 0;

        int mxMask = (1 << n);

        vector<int> good(mxMask), dp(mxMask);
        dp[0] = 1;

        for (int mask = 0; mask < mxMask; ++mask)
        {
            good[mask] = 1;
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < n; ++j)
                    if ((mask & (1 << i)) and (mask & (1 << j)) and (graph[i][j] or graph[j][i]))
                        good[mask] = false;
        }

        for (int mask = 1; mask < mxMask; ++mask)
            for (int sub = mask; sub > 0; sub = (sub - 1) & mask)
                if (good[sub])
                {
                    // cout << mask << " " << sub << "!\n";
                    if (__popcount(sub))
                        dp[mask] = (dp[mask] + dp[mask ^ sub] + MODFFT) % MODFFT;
                    else
                        dp[mask] = (dp[mask] - dp[mask ^ sub] + MODFFT) % MODFFT;
                }
        // cout << dp << "!\n";

        cout << (((dp[mxMask - 1] * m) % MODFFT) * invert(2, MODFFT)) % MODFFT << "\n";
    }
};

main()
{
    boost();
    int q = 1;
    // cin >> q;
    for (int i = 0; i < q; i++)
    {
        test t;
        t.solve(i);
    }
    return 0;
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//
//                                                                                    //
//                               Coded by Der_Vlἀpos                                  //
//                                                                                    //
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//

Compilation message

amusementpark.cpp: In member function 'void test::solve(long long int)':
amusementpark.cpp:167:13: warning: unused variable 'res' [-Wunused-variable]
  167 |         int res = 0;
      |             ^~~
amusementpark.cpp: At global scope:
amusementpark.cpp:199:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  199 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -