Submission #1011146

# Submission time Handle Problem Language Result Execution time Memory
1011146 2024-06-30T00:20:28 Z Oz121 Amusement Park (CEOI19_amusementpark) Java 11
63 / 100
3000 ms 29700 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 = 1;j<(1<<num);j++) {
                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);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 39 ms 22536 KB Output is correct
2 Correct 38 ms 24736 KB Output is correct
3 Correct 40 ms 21988 KB Output is correct
4 Correct 44 ms 22144 KB Output is correct
5 Correct 41 ms 26580 KB Output is correct
6 Correct 38 ms 22408 KB Output is correct
7 Correct 42 ms 24212 KB Output is correct
8 Correct 47 ms 24240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 22536 KB Output is correct
2 Correct 38 ms 24736 KB Output is correct
3 Correct 40 ms 21988 KB Output is correct
4 Correct 44 ms 22144 KB Output is correct
5 Correct 41 ms 26580 KB Output is correct
6 Correct 38 ms 22408 KB Output is correct
7 Correct 42 ms 24212 KB Output is correct
8 Correct 47 ms 24240 KB Output is correct
9 Correct 42 ms 26280 KB Output is correct
10 Correct 40 ms 22620 KB Output is correct
11 Correct 42 ms 22448 KB Output is correct
12 Correct 42 ms 22140 KB Output is correct
13 Correct 48 ms 21792 KB Output is correct
14 Correct 41 ms 24596 KB Output is correct
15 Correct 41 ms 22916 KB Output is correct
16 Correct 39 ms 22624 KB Output is correct
17 Correct 42 ms 26292 KB Output is correct
18 Correct 44 ms 22864 KB Output is correct
19 Correct 45 ms 22800 KB Output is correct
20 Correct 46 ms 22496 KB Output is correct
21 Correct 45 ms 22592 KB Output is correct
22 Correct 46 ms 22836 KB Output is correct
23 Correct 43 ms 22184 KB Output is correct
24 Correct 45 ms 22584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 22536 KB Output is correct
2 Correct 38 ms 24736 KB Output is correct
3 Correct 40 ms 21988 KB Output is correct
4 Correct 44 ms 22144 KB Output is correct
5 Correct 41 ms 26580 KB Output is correct
6 Correct 38 ms 22408 KB Output is correct
7 Correct 42 ms 24212 KB Output is correct
8 Correct 47 ms 24240 KB Output is correct
9 Correct 42 ms 26280 KB Output is correct
10 Correct 40 ms 22620 KB Output is correct
11 Correct 42 ms 22448 KB Output is correct
12 Correct 42 ms 22140 KB Output is correct
13 Correct 48 ms 21792 KB Output is correct
14 Correct 41 ms 24596 KB Output is correct
15 Correct 41 ms 22916 KB Output is correct
16 Correct 39 ms 22624 KB Output is correct
17 Correct 42 ms 26292 KB Output is correct
18 Correct 44 ms 22864 KB Output is correct
19 Correct 45 ms 22800 KB Output is correct
20 Correct 46 ms 22496 KB Output is correct
21 Correct 45 ms 22592 KB Output is correct
22 Correct 46 ms 22836 KB Output is correct
23 Correct 43 ms 22184 KB Output is correct
24 Correct 45 ms 22584 KB Output is correct
25 Correct 49 ms 22744 KB Output is correct
26 Correct 50 ms 22752 KB Output is correct
27 Correct 48 ms 23920 KB Output is correct
28 Correct 46 ms 22740 KB Output is correct
29 Correct 47 ms 22744 KB Output is correct
30 Correct 47 ms 23336 KB Output is correct
31 Correct 48 ms 22808 KB Output is correct
32 Correct 53 ms 22916 KB Output is correct
33 Correct 48 ms 22596 KB Output is correct
34 Correct 48 ms 25016 KB Output is correct
35 Correct 47 ms 22736 KB Output is correct
36 Correct 51 ms 22440 KB Output is correct
37 Correct 50 ms 22768 KB Output is correct
38 Correct 48 ms 22648 KB Output is correct
39 Correct 52 ms 22648 KB Output is correct
40 Correct 53 ms 22432 KB Output is correct
41 Correct 55 ms 22824 KB Output is correct
42 Correct 50 ms 22656 KB Output is correct
43 Correct 57 ms 22784 KB Output is correct
44 Correct 57 ms 25104 KB Output is correct
45 Correct 56 ms 24608 KB Output is correct
46 Correct 58 ms 22948 KB Output is correct
47 Correct 52 ms 22740 KB Output is correct
48 Correct 51 ms 22776 KB Output is correct
49 Correct 53 ms 22680 KB Output is correct
50 Correct 53 ms 22776 KB Output is correct
51 Correct 53 ms 22904 KB Output is correct
52 Correct 55 ms 23084 KB Output is correct
53 Correct 61 ms 22640 KB Output is correct
54 Correct 60 ms 22724 KB Output is correct
55 Correct 57 ms 23028 KB Output is correct
56 Correct 72 ms 23096 KB Output is correct
57 Correct 63 ms 23156 KB Output is correct
58 Correct 66 ms 25476 KB Output is correct
59 Correct 67 ms 29700 KB Output is correct
60 Correct 64 ms 23528 KB Output is correct
61 Correct 58 ms 23028 KB Output is correct
62 Correct 59 ms 22352 KB Output is correct
63 Correct 61 ms 22548 KB Output is correct
64 Correct 63 ms 23024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 22536 KB Output is correct
2 Correct 38 ms 24736 KB Output is correct
3 Correct 40 ms 21988 KB Output is correct
4 Correct 44 ms 22144 KB Output is correct
5 Correct 41 ms 26580 KB Output is correct
6 Correct 38 ms 22408 KB Output is correct
7 Correct 42 ms 24212 KB Output is correct
8 Correct 47 ms 24240 KB Output is correct
9 Correct 42 ms 26280 KB Output is correct
10 Correct 40 ms 22620 KB Output is correct
11 Correct 42 ms 22448 KB Output is correct
12 Correct 42 ms 22140 KB Output is correct
13 Correct 48 ms 21792 KB Output is correct
14 Correct 41 ms 24596 KB Output is correct
15 Correct 41 ms 22916 KB Output is correct
16 Correct 39 ms 22624 KB Output is correct
17 Correct 42 ms 26292 KB Output is correct
18 Correct 44 ms 22864 KB Output is correct
19 Correct 45 ms 22800 KB Output is correct
20 Correct 46 ms 22496 KB Output is correct
21 Correct 45 ms 22592 KB Output is correct
22 Correct 46 ms 22836 KB Output is correct
23 Correct 43 ms 22184 KB Output is correct
24 Correct 45 ms 22584 KB Output is correct
25 Correct 49 ms 22744 KB Output is correct
26 Correct 50 ms 22752 KB Output is correct
27 Correct 48 ms 23920 KB Output is correct
28 Correct 46 ms 22740 KB Output is correct
29 Correct 47 ms 22744 KB Output is correct
30 Correct 47 ms 23336 KB Output is correct
31 Correct 48 ms 22808 KB Output is correct
32 Correct 53 ms 22916 KB Output is correct
33 Correct 48 ms 22596 KB Output is correct
34 Correct 48 ms 25016 KB Output is correct
35 Correct 47 ms 22736 KB Output is correct
36 Correct 51 ms 22440 KB Output is correct
37 Correct 50 ms 22768 KB Output is correct
38 Correct 48 ms 22648 KB Output is correct
39 Correct 52 ms 22648 KB Output is correct
40 Correct 53 ms 22432 KB Output is correct
41 Correct 55 ms 22824 KB Output is correct
42 Correct 50 ms 22656 KB Output is correct
43 Correct 57 ms 22784 KB Output is correct
44 Correct 57 ms 25104 KB Output is correct
45 Correct 56 ms 24608 KB Output is correct
46 Correct 58 ms 22948 KB Output is correct
47 Correct 52 ms 22740 KB Output is correct
48 Correct 51 ms 22776 KB Output is correct
49 Correct 53 ms 22680 KB Output is correct
50 Correct 53 ms 22776 KB Output is correct
51 Correct 53 ms 22904 KB Output is correct
52 Correct 55 ms 23084 KB Output is correct
53 Correct 61 ms 22640 KB Output is correct
54 Correct 60 ms 22724 KB Output is correct
55 Correct 57 ms 23028 KB Output is correct
56 Correct 72 ms 23096 KB Output is correct
57 Correct 63 ms 23156 KB Output is correct
58 Correct 66 ms 25476 KB Output is correct
59 Correct 67 ms 29700 KB Output is correct
60 Correct 64 ms 23528 KB Output is correct
61 Correct 58 ms 23028 KB Output is correct
62 Correct 59 ms 22352 KB Output is correct
63 Correct 61 ms 22548 KB Output is correct
64 Correct 63 ms 23024 KB Output is correct
65 Correct 220 ms 24076 KB Output is correct
66 Correct 229 ms 24556 KB Output is correct
67 Correct 232 ms 26612 KB Output is correct
68 Correct 206 ms 24928 KB Output is correct
69 Correct 280 ms 23980 KB Output is correct
70 Correct 287 ms 26024 KB Output is correct
71 Correct 271 ms 23924 KB Output is correct
72 Correct 277 ms 23848 KB Output is correct
73 Correct 246 ms 22372 KB Output is correct
74 Correct 238 ms 20076 KB Output is correct
75 Correct 252 ms 20404 KB Output is correct
76 Correct 235 ms 16068 KB Output is correct
77 Correct 643 ms 19300 KB Output is correct
78 Correct 597 ms 17304 KB Output is correct
79 Correct 601 ms 24600 KB Output is correct
80 Correct 630 ms 23288 KB Output is correct
81 Correct 600 ms 24424 KB Output is correct
82 Correct 600 ms 24760 KB Output is correct
83 Correct 577 ms 24544 KB Output is correct
84 Correct 591 ms 25108 KB Output is correct
85 Correct 831 ms 23832 KB Output is correct
86 Correct 752 ms 19472 KB Output is correct
87 Correct 746 ms 23860 KB Output is correct
88 Correct 714 ms 24216 KB Output is correct
89 Correct 711 ms 20604 KB Output is correct
90 Correct 677 ms 17668 KB Output is correct
91 Correct 643 ms 20032 KB Output is correct
92 Correct 668 ms 22072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 22536 KB Output is correct
2 Correct 38 ms 24736 KB Output is correct
3 Correct 40 ms 21988 KB Output is correct
4 Correct 44 ms 22144 KB Output is correct
5 Correct 41 ms 26580 KB Output is correct
6 Correct 38 ms 22408 KB Output is correct
7 Correct 42 ms 24212 KB Output is correct
8 Correct 47 ms 24240 KB Output is correct
9 Correct 42 ms 26280 KB Output is correct
10 Correct 40 ms 22620 KB Output is correct
11 Correct 42 ms 22448 KB Output is correct
12 Correct 42 ms 22140 KB Output is correct
13 Correct 48 ms 21792 KB Output is correct
14 Correct 41 ms 24596 KB Output is correct
15 Correct 41 ms 22916 KB Output is correct
16 Correct 39 ms 22624 KB Output is correct
17 Correct 42 ms 26292 KB Output is correct
18 Correct 44 ms 22864 KB Output is correct
19 Correct 45 ms 22800 KB Output is correct
20 Correct 46 ms 22496 KB Output is correct
21 Correct 45 ms 22592 KB Output is correct
22 Correct 46 ms 22836 KB Output is correct
23 Correct 43 ms 22184 KB Output is correct
24 Correct 45 ms 22584 KB Output is correct
25 Correct 49 ms 22744 KB Output is correct
26 Correct 50 ms 22752 KB Output is correct
27 Correct 48 ms 23920 KB Output is correct
28 Correct 46 ms 22740 KB Output is correct
29 Correct 47 ms 22744 KB Output is correct
30 Correct 47 ms 23336 KB Output is correct
31 Correct 48 ms 22808 KB Output is correct
32 Correct 53 ms 22916 KB Output is correct
33 Correct 48 ms 22596 KB Output is correct
34 Correct 48 ms 25016 KB Output is correct
35 Correct 47 ms 22736 KB Output is correct
36 Correct 51 ms 22440 KB Output is correct
37 Correct 50 ms 22768 KB Output is correct
38 Correct 48 ms 22648 KB Output is correct
39 Correct 52 ms 22648 KB Output is correct
40 Correct 53 ms 22432 KB Output is correct
41 Correct 55 ms 22824 KB Output is correct
42 Correct 50 ms 22656 KB Output is correct
43 Correct 57 ms 22784 KB Output is correct
44 Correct 57 ms 25104 KB Output is correct
45 Correct 56 ms 24608 KB Output is correct
46 Correct 58 ms 22948 KB Output is correct
47 Correct 52 ms 22740 KB Output is correct
48 Correct 51 ms 22776 KB Output is correct
49 Correct 53 ms 22680 KB Output is correct
50 Correct 53 ms 22776 KB Output is correct
51 Correct 53 ms 22904 KB Output is correct
52 Correct 55 ms 23084 KB Output is correct
53 Correct 61 ms 22640 KB Output is correct
54 Correct 60 ms 22724 KB Output is correct
55 Correct 57 ms 23028 KB Output is correct
56 Correct 72 ms 23096 KB Output is correct
57 Correct 63 ms 23156 KB Output is correct
58 Correct 66 ms 25476 KB Output is correct
59 Correct 67 ms 29700 KB Output is correct
60 Correct 64 ms 23528 KB Output is correct
61 Correct 58 ms 23028 KB Output is correct
62 Correct 59 ms 22352 KB Output is correct
63 Correct 61 ms 22548 KB Output is correct
64 Correct 63 ms 23024 KB Output is correct
65 Correct 220 ms 24076 KB Output is correct
66 Correct 229 ms 24556 KB Output is correct
67 Correct 232 ms 26612 KB Output is correct
68 Correct 206 ms 24928 KB Output is correct
69 Correct 280 ms 23980 KB Output is correct
70 Correct 287 ms 26024 KB Output is correct
71 Correct 271 ms 23924 KB Output is correct
72 Correct 277 ms 23848 KB Output is correct
73 Correct 246 ms 22372 KB Output is correct
74 Correct 238 ms 20076 KB Output is correct
75 Correct 252 ms 20404 KB Output is correct
76 Correct 235 ms 16068 KB Output is correct
77 Correct 643 ms 19300 KB Output is correct
78 Correct 597 ms 17304 KB Output is correct
79 Correct 601 ms 24600 KB Output is correct
80 Correct 630 ms 23288 KB Output is correct
81 Correct 600 ms 24424 KB Output is correct
82 Correct 600 ms 24760 KB Output is correct
83 Correct 577 ms 24544 KB Output is correct
84 Correct 591 ms 25108 KB Output is correct
85 Correct 831 ms 23832 KB Output is correct
86 Correct 752 ms 19472 KB Output is correct
87 Correct 746 ms 23860 KB Output is correct
88 Correct 714 ms 24216 KB Output is correct
89 Correct 711 ms 20604 KB Output is correct
90 Correct 677 ms 17668 KB Output is correct
91 Correct 643 ms 20032 KB Output is correct
92 Correct 668 ms 22072 KB Output is correct
93 Execution timed out 3017 ms 24604 KB Time limit exceeded
94 Halted 0 ms 0 KB -