답안 #806876

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
806876 2023-08-04T10:43:15 Z PanosPask Amusement Park (CEOI19_amusementpark) C++14
0 / 100
1 ms 304 KB
#include <bits/stdc++.h>
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define CHECK_BIT(val, pos) (val & (1 << pos))

using namespace std;

const int MOD = (int)1e9 + 7;

typedef long long ll;
typedef pair<int, int> pi;

int N, M;
vector<vector<int>> adj_list;

// dp[s]: Total cost and total number of ways
vector<pi> dp;

void add(int& a, int b)
{
    a += b;
    if (a > MOD)
        a -= MOD;
}

void add(pi& a, pi b)
{
    add(a.f, b.f);
    add(a.s, b.s);
}

int main(void)
{
    scanf("%d %d", &N, &M);

    adj_list.resize(N);
    for (int i = 0; i < M; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        u--; v--;

        adj_list[u].pb(v);
    }

    dp.resize(1 << N);
    dp[0] = mp(0, 1);
    for (int i = 0; i < 1 << N; i++) {
        for (int u = 0; u < N; u++) {
            if (CHECK_BIT(i, u))
                continue;

            int res = dp[i].f;
            int times = dp[i].s;
            for (auto v : adj_list[u]) {
                if (CHECK_BIT(i, v)) {
                    add(res, times);
                }
            }

            add(dp[i ^ (1 << u)], mp(res, times));
        }
    }

    printf("%d\n", dp[(1 << N) - 1].f);
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%d %d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~
amusementpark.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -