Submission #1362067
Source Code Expand
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskF solver = new TaskF(); solver.solve(1, in, out); out.close(); } static class TaskF { static final long MODULO = (long) (1e9 + 7); public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); int[] outgo = new int[n]; int[] incom = new int[n]; for (int i = 0; i < m; ++i) { int x = in.nextInt() - 1; int y = in.nextInt() - 1; outgo[x] |= 1 << y; incom[y] |= 1 << x; } int[] ways = new int[1 << n]; for (int s = 1; s < ways.length; ++s) { if ((s & 3) != 3) continue; long cw = 0; outer: for (int t = s; t > 0; t = (t - 1) & s) { if ((t & 3) == 3) continue; int rem = s ^ t; if ((t & 3) == 0 && ways[rem] == 0) continue; long w = 1; for (int u = 0; u < n; ++u) if ((rem & (1 << u)) != 0) { int oup = outgo[u] & t; int cnt = Integer.bitCount(oup); if (cnt == 0) { continue outer; } w *= (1 << cnt) - 1; w %= MODULO; int inp = incom[u] & t; w *= 1 << Integer.bitCount(inp); w %= MODULO; } long ow; if ((t & 3) == 0) { ow = ways[rem]; } else { ow = 1; for (int u = 0; u < n; ++u) if ((rem & (1 << u)) != 0) { ow *= 1 << Integer.bitCount(outgo[u] & rem); ow %= MODULO; } } cw += ow * w; cw %= MODULO; } ways[s] = (int) cw; } out.println(ways[ways.length - 1]); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Submission Info
Submission Time | |
---|---|
Task | F - Games on DAG |
User | Petr |
Language | Java8 (OpenJDK 1.8.0) |
Score | 1600 |
Code Size | 3774 Byte |
Status | AC |
Exec Time | 697 ms |
Memory | 22672 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1600 / 1600 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 71 ms | 18388 KB |
0_01.txt | AC | 70 ms | 19412 KB |
0_02.txt | AC | 69 ms | 17876 KB |
0_03.txt | AC | 71 ms | 20564 KB |
1_00.txt | AC | 69 ms | 18516 KB |
1_01.txt | AC | 146 ms | 19144 KB |
1_02.txt | AC | 116 ms | 19156 KB |
1_03.txt | AC | 653 ms | 22220 KB |
1_04.txt | AC | 697 ms | 20644 KB |
1_05.txt | AC | 644 ms | 22220 KB |
1_06.txt | AC | 617 ms | 20540 KB |
1_07.txt | AC | 630 ms | 19920 KB |
1_08.txt | AC | 654 ms | 20540 KB |
1_09.txt | AC | 635 ms | 18640 KB |
1_10.txt | AC | 615 ms | 20588 KB |
1_11.txt | AC | 586 ms | 19908 KB |
1_12.txt | AC | 623 ms | 20288 KB |
1_13.txt | AC | 648 ms | 20560 KB |
1_14.txt | AC | 640 ms | 18764 KB |
1_15.txt | AC | 596 ms | 20544 KB |
1_16.txt | AC | 626 ms | 22220 KB |
1_17.txt | AC | 665 ms | 18272 KB |
1_18.txt | AC | 591 ms | 19792 KB |
1_19.txt | AC | 606 ms | 19268 KB |
1_20.txt | AC | 248 ms | 20048 KB |
1_21.txt | AC | 95 ms | 21076 KB |
1_22.txt | AC | 440 ms | 21712 KB |
1_23.txt | AC | 527 ms | 20032 KB |
1_24.txt | AC | 189 ms | 22672 KB |
1_25.txt | AC | 78 ms | 19540 KB |
1_26.txt | AC | 595 ms | 22348 KB |
1_27.txt | AC | 120 ms | 20048 KB |
1_28.txt | AC | 137 ms | 19540 KB |
1_29.txt | AC | 149 ms | 22220 KB |
1_30.txt | AC | 99 ms | 20052 KB |
1_31.txt | AC | 630 ms | 20304 KB |
1_32.txt | AC | 147 ms | 19276 KB |
1_33.txt | AC | 126 ms | 19408 KB |
1_34.txt | AC | 226 ms | 22320 KB |
1_35.txt | AC | 142 ms | 22092 KB |