Submission #1011147

# Submission time Handle Problem Language Result Execution time Memory
1011147 2024-06-30T00:27:04 Z Oz121 Amusement Park (CEOI19_amusementpark) Java 11
63 / 100
3000 ms 31760 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
        ArrayList<Integer> indep = new ArrayList<>();
        for (int i = 0;i<(1<<num);i++) {
            boolean temp = true;
            for (int j = 0;j<num;j++) {
                if ((i&(1<<j))==0) continue;

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

            if (temp) indep.add(i);
        }

        //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 : indep) {
                if ((i|j)!=i) 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;
            }
        }

        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 51 ms 26556 KB Output is correct
2 Correct 46 ms 22272 KB Output is correct
3 Correct 45 ms 24336 KB Output is correct
4 Correct 40 ms 21948 KB Output is correct
5 Correct 42 ms 22112 KB Output is correct
6 Correct 43 ms 24208 KB Output is correct
7 Correct 42 ms 22696 KB Output is correct
8 Correct 42 ms 24484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 26556 KB Output is correct
2 Correct 46 ms 22272 KB Output is correct
3 Correct 45 ms 24336 KB Output is correct
4 Correct 40 ms 21948 KB Output is correct
5 Correct 42 ms 22112 KB Output is correct
6 Correct 43 ms 24208 KB Output is correct
7 Correct 42 ms 22696 KB Output is correct
8 Correct 42 ms 24484 KB Output is correct
9 Correct 40 ms 22452 KB Output is correct
10 Correct 38 ms 22476 KB Output is correct
11 Correct 41 ms 22072 KB Output is correct
12 Correct 43 ms 22156 KB Output is correct
13 Correct 48 ms 24148 KB Output is correct
14 Correct 46 ms 22448 KB Output is correct
15 Correct 45 ms 22536 KB Output is correct
16 Correct 46 ms 22432 KB Output is correct
17 Correct 50 ms 22116 KB Output is correct
18 Correct 45 ms 22644 KB Output is correct
19 Correct 45 ms 22356 KB Output is correct
20 Correct 46 ms 21832 KB Output is correct
21 Correct 47 ms 22532 KB Output is correct
22 Correct 45 ms 22440 KB Output is correct
23 Correct 47 ms 21868 KB Output is correct
24 Correct 46 ms 22244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 26556 KB Output is correct
2 Correct 46 ms 22272 KB Output is correct
3 Correct 45 ms 24336 KB Output is correct
4 Correct 40 ms 21948 KB Output is correct
5 Correct 42 ms 22112 KB Output is correct
6 Correct 43 ms 24208 KB Output is correct
7 Correct 42 ms 22696 KB Output is correct
8 Correct 42 ms 24484 KB Output is correct
9 Correct 40 ms 22452 KB Output is correct
10 Correct 38 ms 22476 KB Output is correct
11 Correct 41 ms 22072 KB Output is correct
12 Correct 43 ms 22156 KB Output is correct
13 Correct 48 ms 24148 KB Output is correct
14 Correct 46 ms 22448 KB Output is correct
15 Correct 45 ms 22536 KB Output is correct
16 Correct 46 ms 22432 KB Output is correct
17 Correct 50 ms 22116 KB Output is correct
18 Correct 45 ms 22644 KB Output is correct
19 Correct 45 ms 22356 KB Output is correct
20 Correct 46 ms 21832 KB Output is correct
21 Correct 47 ms 22532 KB Output is correct
22 Correct 45 ms 22440 KB Output is correct
23 Correct 47 ms 21868 KB Output is correct
24 Correct 46 ms 22244 KB Output is correct
25 Correct 51 ms 22712 KB Output is correct
26 Correct 48 ms 26172 KB Output is correct
27 Correct 48 ms 26468 KB Output is correct
28 Correct 48 ms 26232 KB Output is correct
29 Correct 46 ms 22744 KB Output is correct
30 Correct 46 ms 22580 KB Output is correct
31 Correct 46 ms 22928 KB Output is correct
32 Correct 57 ms 22632 KB Output is correct
33 Correct 54 ms 22580 KB Output is correct
34 Correct 51 ms 24420 KB Output is correct
35 Correct 55 ms 22504 KB Output is correct
36 Correct 49 ms 22400 KB Output is correct
37 Correct 49 ms 24712 KB Output is correct
38 Correct 47 ms 26332 KB Output is correct
39 Correct 59 ms 23352 KB Output is correct
40 Correct 58 ms 23152 KB Output is correct
41 Correct 58 ms 23016 KB Output is correct
42 Correct 60 ms 22996 KB Output is correct
43 Correct 55 ms 22740 KB Output is correct
44 Correct 57 ms 22424 KB Output is correct
45 Correct 57 ms 22692 KB Output is correct
46 Correct 55 ms 22528 KB Output is correct
47 Correct 49 ms 22868 KB Output is correct
48 Correct 59 ms 25036 KB Output is correct
49 Correct 57 ms 21256 KB Output is correct
50 Correct 60 ms 23032 KB Output is correct
51 Correct 62 ms 22960 KB Output is correct
52 Correct 63 ms 23080 KB Output is correct
53 Correct 59 ms 23312 KB Output is correct
54 Correct 64 ms 24668 KB Output is correct
55 Correct 59 ms 27252 KB Output is correct
56 Correct 64 ms 23336 KB Output is correct
57 Correct 59 ms 23276 KB Output is correct
58 Correct 60 ms 23768 KB Output is correct
59 Correct 65 ms 22356 KB Output is correct
60 Correct 63 ms 24200 KB Output is correct
61 Correct 65 ms 23156 KB Output is correct
62 Correct 61 ms 24984 KB Output is correct
63 Correct 60 ms 23020 KB Output is correct
64 Correct 60 ms 23108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 26556 KB Output is correct
2 Correct 46 ms 22272 KB Output is correct
3 Correct 45 ms 24336 KB Output is correct
4 Correct 40 ms 21948 KB Output is correct
5 Correct 42 ms 22112 KB Output is correct
6 Correct 43 ms 24208 KB Output is correct
7 Correct 42 ms 22696 KB Output is correct
8 Correct 42 ms 24484 KB Output is correct
9 Correct 40 ms 22452 KB Output is correct
10 Correct 38 ms 22476 KB Output is correct
11 Correct 41 ms 22072 KB Output is correct
12 Correct 43 ms 22156 KB Output is correct
13 Correct 48 ms 24148 KB Output is correct
14 Correct 46 ms 22448 KB Output is correct
15 Correct 45 ms 22536 KB Output is correct
16 Correct 46 ms 22432 KB Output is correct
17 Correct 50 ms 22116 KB Output is correct
18 Correct 45 ms 22644 KB Output is correct
19 Correct 45 ms 22356 KB Output is correct
20 Correct 46 ms 21832 KB Output is correct
21 Correct 47 ms 22532 KB Output is correct
22 Correct 45 ms 22440 KB Output is correct
23 Correct 47 ms 21868 KB Output is correct
24 Correct 46 ms 22244 KB Output is correct
25 Correct 51 ms 22712 KB Output is correct
26 Correct 48 ms 26172 KB Output is correct
27 Correct 48 ms 26468 KB Output is correct
28 Correct 48 ms 26232 KB Output is correct
29 Correct 46 ms 22744 KB Output is correct
30 Correct 46 ms 22580 KB Output is correct
31 Correct 46 ms 22928 KB Output is correct
32 Correct 57 ms 22632 KB Output is correct
33 Correct 54 ms 22580 KB Output is correct
34 Correct 51 ms 24420 KB Output is correct
35 Correct 55 ms 22504 KB Output is correct
36 Correct 49 ms 22400 KB Output is correct
37 Correct 49 ms 24712 KB Output is correct
38 Correct 47 ms 26332 KB Output is correct
39 Correct 59 ms 23352 KB Output is correct
40 Correct 58 ms 23152 KB Output is correct
41 Correct 58 ms 23016 KB Output is correct
42 Correct 60 ms 22996 KB Output is correct
43 Correct 55 ms 22740 KB Output is correct
44 Correct 57 ms 22424 KB Output is correct
45 Correct 57 ms 22692 KB Output is correct
46 Correct 55 ms 22528 KB Output is correct
47 Correct 49 ms 22868 KB Output is correct
48 Correct 59 ms 25036 KB Output is correct
49 Correct 57 ms 21256 KB Output is correct
50 Correct 60 ms 23032 KB Output is correct
51 Correct 62 ms 22960 KB Output is correct
52 Correct 63 ms 23080 KB Output is correct
53 Correct 59 ms 23312 KB Output is correct
54 Correct 64 ms 24668 KB Output is correct
55 Correct 59 ms 27252 KB Output is correct
56 Correct 64 ms 23336 KB Output is correct
57 Correct 59 ms 23276 KB Output is correct
58 Correct 60 ms 23768 KB Output is correct
59 Correct 65 ms 22356 KB Output is correct
60 Correct 63 ms 24200 KB Output is correct
61 Correct 65 ms 23156 KB Output is correct
62 Correct 61 ms 24984 KB Output is correct
63 Correct 60 ms 23020 KB Output is correct
64 Correct 60 ms 23108 KB Output is correct
65 Correct 101 ms 26128 KB Output is correct
66 Correct 103 ms 28092 KB Output is correct
67 Correct 93 ms 24116 KB Output is correct
68 Correct 94 ms 26016 KB Output is correct
69 Correct 544 ms 23736 KB Output is correct
70 Correct 327 ms 24084 KB Output is correct
71 Correct 328 ms 24340 KB Output is correct
72 Correct 319 ms 24352 KB Output is correct
73 Correct 214 ms 24128 KB Output is correct
74 Correct 215 ms 23764 KB Output is correct
75 Correct 213 ms 24384 KB Output is correct
76 Correct 218 ms 24584 KB Output is correct
77 Correct 209 ms 24696 KB Output is correct
78 Correct 184 ms 24656 KB Output is correct
79 Correct 133 ms 28356 KB Output is correct
80 Correct 127 ms 24784 KB Output is correct
81 Correct 120 ms 26500 KB Output is correct
82 Correct 118 ms 24428 KB Output is correct
83 Correct 96 ms 26564 KB Output is correct
84 Correct 100 ms 24600 KB Output is correct
85 Correct 1704 ms 25096 KB Output is correct
86 Correct 923 ms 24776 KB Output is correct
87 Correct 1006 ms 24672 KB Output is correct
88 Correct 936 ms 25052 KB Output is correct
89 Correct 548 ms 24732 KB Output is correct
90 Correct 530 ms 24984 KB Output is correct
91 Correct 564 ms 24572 KB Output is correct
92 Correct 577 ms 25128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 26556 KB Output is correct
2 Correct 46 ms 22272 KB Output is correct
3 Correct 45 ms 24336 KB Output is correct
4 Correct 40 ms 21948 KB Output is correct
5 Correct 42 ms 22112 KB Output is correct
6 Correct 43 ms 24208 KB Output is correct
7 Correct 42 ms 22696 KB Output is correct
8 Correct 42 ms 24484 KB Output is correct
9 Correct 40 ms 22452 KB Output is correct
10 Correct 38 ms 22476 KB Output is correct
11 Correct 41 ms 22072 KB Output is correct
12 Correct 43 ms 22156 KB Output is correct
13 Correct 48 ms 24148 KB Output is correct
14 Correct 46 ms 22448 KB Output is correct
15 Correct 45 ms 22536 KB Output is correct
16 Correct 46 ms 22432 KB Output is correct
17 Correct 50 ms 22116 KB Output is correct
18 Correct 45 ms 22644 KB Output is correct
19 Correct 45 ms 22356 KB Output is correct
20 Correct 46 ms 21832 KB Output is correct
21 Correct 47 ms 22532 KB Output is correct
22 Correct 45 ms 22440 KB Output is correct
23 Correct 47 ms 21868 KB Output is correct
24 Correct 46 ms 22244 KB Output is correct
25 Correct 51 ms 22712 KB Output is correct
26 Correct 48 ms 26172 KB Output is correct
27 Correct 48 ms 26468 KB Output is correct
28 Correct 48 ms 26232 KB Output is correct
29 Correct 46 ms 22744 KB Output is correct
30 Correct 46 ms 22580 KB Output is correct
31 Correct 46 ms 22928 KB Output is correct
32 Correct 57 ms 22632 KB Output is correct
33 Correct 54 ms 22580 KB Output is correct
34 Correct 51 ms 24420 KB Output is correct
35 Correct 55 ms 22504 KB Output is correct
36 Correct 49 ms 22400 KB Output is correct
37 Correct 49 ms 24712 KB Output is correct
38 Correct 47 ms 26332 KB Output is correct
39 Correct 59 ms 23352 KB Output is correct
40 Correct 58 ms 23152 KB Output is correct
41 Correct 58 ms 23016 KB Output is correct
42 Correct 60 ms 22996 KB Output is correct
43 Correct 55 ms 22740 KB Output is correct
44 Correct 57 ms 22424 KB Output is correct
45 Correct 57 ms 22692 KB Output is correct
46 Correct 55 ms 22528 KB Output is correct
47 Correct 49 ms 22868 KB Output is correct
48 Correct 59 ms 25036 KB Output is correct
49 Correct 57 ms 21256 KB Output is correct
50 Correct 60 ms 23032 KB Output is correct
51 Correct 62 ms 22960 KB Output is correct
52 Correct 63 ms 23080 KB Output is correct
53 Correct 59 ms 23312 KB Output is correct
54 Correct 64 ms 24668 KB Output is correct
55 Correct 59 ms 27252 KB Output is correct
56 Correct 64 ms 23336 KB Output is correct
57 Correct 59 ms 23276 KB Output is correct
58 Correct 60 ms 23768 KB Output is correct
59 Correct 65 ms 22356 KB Output is correct
60 Correct 63 ms 24200 KB Output is correct
61 Correct 65 ms 23156 KB Output is correct
62 Correct 61 ms 24984 KB Output is correct
63 Correct 60 ms 23020 KB Output is correct
64 Correct 60 ms 23108 KB Output is correct
65 Correct 101 ms 26128 KB Output is correct
66 Correct 103 ms 28092 KB Output is correct
67 Correct 93 ms 24116 KB Output is correct
68 Correct 94 ms 26016 KB Output is correct
69 Correct 544 ms 23736 KB Output is correct
70 Correct 327 ms 24084 KB Output is correct
71 Correct 328 ms 24340 KB Output is correct
72 Correct 319 ms 24352 KB Output is correct
73 Correct 214 ms 24128 KB Output is correct
74 Correct 215 ms 23764 KB Output is correct
75 Correct 213 ms 24384 KB Output is correct
76 Correct 218 ms 24584 KB Output is correct
77 Correct 209 ms 24696 KB Output is correct
78 Correct 184 ms 24656 KB Output is correct
79 Correct 133 ms 28356 KB Output is correct
80 Correct 127 ms 24784 KB Output is correct
81 Correct 120 ms 26500 KB Output is correct
82 Correct 118 ms 24428 KB Output is correct
83 Correct 96 ms 26564 KB Output is correct
84 Correct 100 ms 24600 KB Output is correct
85 Correct 1704 ms 25096 KB Output is correct
86 Correct 923 ms 24776 KB Output is correct
87 Correct 1006 ms 24672 KB Output is correct
88 Correct 936 ms 25052 KB Output is correct
89 Correct 548 ms 24732 KB Output is correct
90 Correct 530 ms 24984 KB Output is correct
91 Correct 564 ms 24572 KB Output is correct
92 Correct 577 ms 25128 KB Output is correct
93 Execution timed out 3068 ms 31760 KB Time limit exceeded
94 Halted 0 ms 0 KB -