답안 #1011148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011148 2024-06-30T00:51:24 Z Oz121 Amusement Park (CEOI19_amusementpark) Java 11
63 / 100
3000 ms 30120 KB
import java.io.*;
import java.util.*;
public class amusementpark {
    public static int mod = 998244353;
    public static void main(String[] args) throws IOException {
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer l1 = new StringTokenizer(scan.readLine());
        int num = Integer.parseInt(l1.nextToken()); int m = Integer.parseInt(l1.nextToken());

        HashMap<Integer, ArrayList<Integer>> graph = new HashMap<>();
        for (int i = 0;i<num;i++) graph.put(i,new ArrayList<>());

        for (int i = 0;i<m;i++) {
            StringTokenizer st = new StringTokenizer(scan.readLine());
            int a = Integer.parseInt(st.nextToken())-1; int b = Integer.parseInt(st.nextToken())-1;
            graph.get(a).add(b);
        }

        //Store if a set i of vertices is independent or not
        boolean[] indep = new boolean[1<<num]; Arrays.fill(indep, true);
        for (int i = 0;i<(1<<num);i++) {
            for (int j = 0;j<num;j++) {
                if ((i&(1<<j))==0) continue;

                for (int k : graph.get(j)) {
                    if ((i&(1<<k))!=0) indep[i] = false;
                }
            }
        }

        //Use DP to count the number of DAGs in the given graph
        long[] dp = new long[1<<num]; //Number of DAGs in the subgraph on the set i of vertices
        dp[0] = 1;

        for (int i = 1;i<(1<<num);i++) {
            for (int j = i;j>0;j = (j-1)&i) {
                if ((i|j)!=i||!indep[j]) continue; //Ensures j is a subset of i

                int prev = i-j;
                dp[i] = (dp[i]+(int) Math.pow(-1,Integer.bitCount(j)+1)*dp[prev])%mod;
                dp[i] = (dp[i]+mod)%mod;
            }
        }

        //System.out.println(Arrays.toString(dp));

        long ans = (dp[(1<<num)-1]*m)%mod;
        ans = (ans%2==0) ? ans/2 : (ans+mod)/2;
        System.out.println(ans);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 22372 KB Output is correct
2 Correct 44 ms 24424 KB Output is correct
3 Correct 53 ms 22224 KB Output is correct
4 Correct 51 ms 22448 KB Output is correct
5 Correct 45 ms 24268 KB Output is correct
6 Correct 45 ms 22248 KB Output is correct
7 Correct 48 ms 22408 KB Output is correct
8 Correct 46 ms 22220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 22372 KB Output is correct
2 Correct 44 ms 24424 KB Output is correct
3 Correct 53 ms 22224 KB Output is correct
4 Correct 51 ms 22448 KB Output is correct
5 Correct 45 ms 24268 KB Output is correct
6 Correct 45 ms 22248 KB Output is correct
7 Correct 48 ms 22408 KB Output is correct
8 Correct 46 ms 22220 KB Output is correct
9 Correct 45 ms 22728 KB Output is correct
10 Correct 46 ms 22148 KB Output is correct
11 Correct 45 ms 26632 KB Output is correct
12 Correct 45 ms 22072 KB Output is correct
13 Correct 44 ms 22692 KB Output is correct
14 Correct 47 ms 22324 KB Output is correct
15 Correct 49 ms 23968 KB Output is correct
16 Correct 45 ms 22484 KB Output is correct
17 Correct 46 ms 26492 KB Output is correct
18 Correct 53 ms 22252 KB Output is correct
19 Correct 45 ms 22164 KB Output is correct
20 Correct 47 ms 22636 KB Output is correct
21 Correct 45 ms 24048 KB Output is correct
22 Correct 46 ms 22424 KB Output is correct
23 Correct 46 ms 24244 KB Output is correct
24 Correct 46 ms 22732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 22372 KB Output is correct
2 Correct 44 ms 24424 KB Output is correct
3 Correct 53 ms 22224 KB Output is correct
4 Correct 51 ms 22448 KB Output is correct
5 Correct 45 ms 24268 KB Output is correct
6 Correct 45 ms 22248 KB Output is correct
7 Correct 48 ms 22408 KB Output is correct
8 Correct 46 ms 22220 KB Output is correct
9 Correct 45 ms 22728 KB Output is correct
10 Correct 46 ms 22148 KB Output is correct
11 Correct 45 ms 26632 KB Output is correct
12 Correct 45 ms 22072 KB Output is correct
13 Correct 44 ms 22692 KB Output is correct
14 Correct 47 ms 22324 KB Output is correct
15 Correct 49 ms 23968 KB Output is correct
16 Correct 45 ms 22484 KB Output is correct
17 Correct 46 ms 26492 KB Output is correct
18 Correct 53 ms 22252 KB Output is correct
19 Correct 45 ms 22164 KB Output is correct
20 Correct 47 ms 22636 KB Output is correct
21 Correct 45 ms 24048 KB Output is correct
22 Correct 46 ms 22424 KB Output is correct
23 Correct 46 ms 24244 KB Output is correct
24 Correct 46 ms 22732 KB Output is correct
25 Correct 48 ms 22388 KB Output is correct
26 Correct 47 ms 22400 KB Output is correct
27 Correct 54 ms 22504 KB Output is correct
28 Correct 46 ms 22392 KB Output is correct
29 Correct 50 ms 22148 KB Output is correct
30 Correct 47 ms 22616 KB Output is correct
31 Correct 48 ms 22428 KB Output is correct
32 Correct 47 ms 22488 KB Output is correct
33 Correct 48 ms 24528 KB Output is correct
34 Correct 47 ms 21880 KB Output is correct
35 Correct 48 ms 22644 KB Output is correct
36 Correct 49 ms 22264 KB Output is correct
37 Correct 55 ms 22136 KB Output is correct
38 Correct 50 ms 22636 KB Output is correct
39 Correct 55 ms 22804 KB Output is correct
40 Correct 55 ms 22132 KB Output is correct
41 Correct 57 ms 22376 KB Output is correct
42 Correct 59 ms 25036 KB Output is correct
43 Correct 68 ms 22160 KB Output is correct
44 Correct 58 ms 22008 KB Output is correct
45 Correct 55 ms 22816 KB Output is correct
46 Correct 57 ms 24800 KB Output is correct
47 Correct 63 ms 22632 KB Output is correct
48 Correct 62 ms 22616 KB Output is correct
49 Correct 58 ms 22692 KB Output is correct
50 Correct 55 ms 22672 KB Output is correct
51 Correct 57 ms 24680 KB Output is correct
52 Correct 60 ms 26948 KB Output is correct
53 Correct 65 ms 26380 KB Output is correct
54 Correct 60 ms 24304 KB Output is correct
55 Correct 64 ms 22796 KB Output is correct
56 Correct 81 ms 23552 KB Output is correct
57 Correct 77 ms 23240 KB Output is correct
58 Correct 71 ms 25920 KB Output is correct
59 Correct 68 ms 23492 KB Output is correct
60 Correct 67 ms 25656 KB Output is correct
61 Correct 62 ms 24956 KB Output is correct
62 Correct 63 ms 24228 KB Output is correct
63 Correct 62 ms 26588 KB Output is correct
64 Correct 65 ms 22256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 22372 KB Output is correct
2 Correct 44 ms 24424 KB Output is correct
3 Correct 53 ms 22224 KB Output is correct
4 Correct 51 ms 22448 KB Output is correct
5 Correct 45 ms 24268 KB Output is correct
6 Correct 45 ms 22248 KB Output is correct
7 Correct 48 ms 22408 KB Output is correct
8 Correct 46 ms 22220 KB Output is correct
9 Correct 45 ms 22728 KB Output is correct
10 Correct 46 ms 22148 KB Output is correct
11 Correct 45 ms 26632 KB Output is correct
12 Correct 45 ms 22072 KB Output is correct
13 Correct 44 ms 22692 KB Output is correct
14 Correct 47 ms 22324 KB Output is correct
15 Correct 49 ms 23968 KB Output is correct
16 Correct 45 ms 22484 KB Output is correct
17 Correct 46 ms 26492 KB Output is correct
18 Correct 53 ms 22252 KB Output is correct
19 Correct 45 ms 22164 KB Output is correct
20 Correct 47 ms 22636 KB Output is correct
21 Correct 45 ms 24048 KB Output is correct
22 Correct 46 ms 22424 KB Output is correct
23 Correct 46 ms 24244 KB Output is correct
24 Correct 46 ms 22732 KB Output is correct
25 Correct 48 ms 22388 KB Output is correct
26 Correct 47 ms 22400 KB Output is correct
27 Correct 54 ms 22504 KB Output is correct
28 Correct 46 ms 22392 KB Output is correct
29 Correct 50 ms 22148 KB Output is correct
30 Correct 47 ms 22616 KB Output is correct
31 Correct 48 ms 22428 KB Output is correct
32 Correct 47 ms 22488 KB Output is correct
33 Correct 48 ms 24528 KB Output is correct
34 Correct 47 ms 21880 KB Output is correct
35 Correct 48 ms 22644 KB Output is correct
36 Correct 49 ms 22264 KB Output is correct
37 Correct 55 ms 22136 KB Output is correct
38 Correct 50 ms 22636 KB Output is correct
39 Correct 55 ms 22804 KB Output is correct
40 Correct 55 ms 22132 KB Output is correct
41 Correct 57 ms 22376 KB Output is correct
42 Correct 59 ms 25036 KB Output is correct
43 Correct 68 ms 22160 KB Output is correct
44 Correct 58 ms 22008 KB Output is correct
45 Correct 55 ms 22816 KB Output is correct
46 Correct 57 ms 24800 KB Output is correct
47 Correct 63 ms 22632 KB Output is correct
48 Correct 62 ms 22616 KB Output is correct
49 Correct 58 ms 22692 KB Output is correct
50 Correct 55 ms 22672 KB Output is correct
51 Correct 57 ms 24680 KB Output is correct
52 Correct 60 ms 26948 KB Output is correct
53 Correct 65 ms 26380 KB Output is correct
54 Correct 60 ms 24304 KB Output is correct
55 Correct 64 ms 22796 KB Output is correct
56 Correct 81 ms 23552 KB Output is correct
57 Correct 77 ms 23240 KB Output is correct
58 Correct 71 ms 25920 KB Output is correct
59 Correct 68 ms 23492 KB Output is correct
60 Correct 67 ms 25656 KB Output is correct
61 Correct 62 ms 24956 KB Output is correct
62 Correct 63 ms 24228 KB Output is correct
63 Correct 62 ms 26588 KB Output is correct
64 Correct 65 ms 22256 KB Output is correct
65 Correct 103 ms 23860 KB Output is correct
66 Correct 97 ms 26880 KB Output is correct
67 Correct 93 ms 24404 KB Output is correct
68 Correct 96 ms 26188 KB Output is correct
69 Correct 156 ms 23732 KB Output is correct
70 Correct 142 ms 23816 KB Output is correct
71 Correct 147 ms 23744 KB Output is correct
72 Correct 144 ms 27604 KB Output is correct
73 Correct 117 ms 24768 KB Output is correct
74 Correct 125 ms 25284 KB Output is correct
75 Correct 117 ms 23772 KB Output is correct
76 Correct 131 ms 24496 KB Output is correct
77 Correct 155 ms 23716 KB Output is correct
78 Correct 129 ms 30120 KB Output is correct
79 Correct 137 ms 24284 KB Output is correct
80 Correct 124 ms 23504 KB Output is correct
81 Correct 124 ms 26440 KB Output is correct
82 Correct 120 ms 24612 KB Output is correct
83 Correct 128 ms 24568 KB Output is correct
84 Correct 114 ms 24412 KB Output is correct
85 Correct 364 ms 28396 KB Output is correct
86 Correct 287 ms 23888 KB Output is correct
87 Correct 287 ms 23948 KB Output is correct
88 Correct 283 ms 23772 KB Output is correct
89 Correct 232 ms 24804 KB Output is correct
90 Correct 226 ms 23472 KB Output is correct
91 Correct 221 ms 23892 KB Output is correct
92 Correct 228 ms 25588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 22372 KB Output is correct
2 Correct 44 ms 24424 KB Output is correct
3 Correct 53 ms 22224 KB Output is correct
4 Correct 51 ms 22448 KB Output is correct
5 Correct 45 ms 24268 KB Output is correct
6 Correct 45 ms 22248 KB Output is correct
7 Correct 48 ms 22408 KB Output is correct
8 Correct 46 ms 22220 KB Output is correct
9 Correct 45 ms 22728 KB Output is correct
10 Correct 46 ms 22148 KB Output is correct
11 Correct 45 ms 26632 KB Output is correct
12 Correct 45 ms 22072 KB Output is correct
13 Correct 44 ms 22692 KB Output is correct
14 Correct 47 ms 22324 KB Output is correct
15 Correct 49 ms 23968 KB Output is correct
16 Correct 45 ms 22484 KB Output is correct
17 Correct 46 ms 26492 KB Output is correct
18 Correct 53 ms 22252 KB Output is correct
19 Correct 45 ms 22164 KB Output is correct
20 Correct 47 ms 22636 KB Output is correct
21 Correct 45 ms 24048 KB Output is correct
22 Correct 46 ms 22424 KB Output is correct
23 Correct 46 ms 24244 KB Output is correct
24 Correct 46 ms 22732 KB Output is correct
25 Correct 48 ms 22388 KB Output is correct
26 Correct 47 ms 22400 KB Output is correct
27 Correct 54 ms 22504 KB Output is correct
28 Correct 46 ms 22392 KB Output is correct
29 Correct 50 ms 22148 KB Output is correct
30 Correct 47 ms 22616 KB Output is correct
31 Correct 48 ms 22428 KB Output is correct
32 Correct 47 ms 22488 KB Output is correct
33 Correct 48 ms 24528 KB Output is correct
34 Correct 47 ms 21880 KB Output is correct
35 Correct 48 ms 22644 KB Output is correct
36 Correct 49 ms 22264 KB Output is correct
37 Correct 55 ms 22136 KB Output is correct
38 Correct 50 ms 22636 KB Output is correct
39 Correct 55 ms 22804 KB Output is correct
40 Correct 55 ms 22132 KB Output is correct
41 Correct 57 ms 22376 KB Output is correct
42 Correct 59 ms 25036 KB Output is correct
43 Correct 68 ms 22160 KB Output is correct
44 Correct 58 ms 22008 KB Output is correct
45 Correct 55 ms 22816 KB Output is correct
46 Correct 57 ms 24800 KB Output is correct
47 Correct 63 ms 22632 KB Output is correct
48 Correct 62 ms 22616 KB Output is correct
49 Correct 58 ms 22692 KB Output is correct
50 Correct 55 ms 22672 KB Output is correct
51 Correct 57 ms 24680 KB Output is correct
52 Correct 60 ms 26948 KB Output is correct
53 Correct 65 ms 26380 KB Output is correct
54 Correct 60 ms 24304 KB Output is correct
55 Correct 64 ms 22796 KB Output is correct
56 Correct 81 ms 23552 KB Output is correct
57 Correct 77 ms 23240 KB Output is correct
58 Correct 71 ms 25920 KB Output is correct
59 Correct 68 ms 23492 KB Output is correct
60 Correct 67 ms 25656 KB Output is correct
61 Correct 62 ms 24956 KB Output is correct
62 Correct 63 ms 24228 KB Output is correct
63 Correct 62 ms 26588 KB Output is correct
64 Correct 65 ms 22256 KB Output is correct
65 Correct 103 ms 23860 KB Output is correct
66 Correct 97 ms 26880 KB Output is correct
67 Correct 93 ms 24404 KB Output is correct
68 Correct 96 ms 26188 KB Output is correct
69 Correct 156 ms 23732 KB Output is correct
70 Correct 142 ms 23816 KB Output is correct
71 Correct 147 ms 23744 KB Output is correct
72 Correct 144 ms 27604 KB Output is correct
73 Correct 117 ms 24768 KB Output is correct
74 Correct 125 ms 25284 KB Output is correct
75 Correct 117 ms 23772 KB Output is correct
76 Correct 131 ms 24496 KB Output is correct
77 Correct 155 ms 23716 KB Output is correct
78 Correct 129 ms 30120 KB Output is correct
79 Correct 137 ms 24284 KB Output is correct
80 Correct 124 ms 23504 KB Output is correct
81 Correct 124 ms 26440 KB Output is correct
82 Correct 120 ms 24612 KB Output is correct
83 Correct 128 ms 24568 KB Output is correct
84 Correct 114 ms 24412 KB Output is correct
85 Correct 364 ms 28396 KB Output is correct
86 Correct 287 ms 23888 KB Output is correct
87 Correct 287 ms 23948 KB Output is correct
88 Correct 283 ms 23772 KB Output is correct
89 Correct 232 ms 24804 KB Output is correct
90 Correct 226 ms 23472 KB Output is correct
91 Correct 221 ms 23892 KB Output is correct
92 Correct 228 ms 25588 KB Output is correct
93 Execution timed out 3077 ms 23916 KB Time limit exceeded
94 Halted 0 ms 0 KB -