Submission #1364751
Source Code Expand
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using SB = System.Text.StringBuilder; //using System.Numerics; using Number = System.Int64; using static System.Math; //using static MathEx; //using P = System.Collections.Generic.KeyValuePair<int, int>; namespace Program { public class Solver { public void Solve() { var n = ri; var m = ri; var g = new int[n]; var rg = new int[n]; var dp = new long[1 << n]; for (int i = 0; i < 1 << n; i++) dp[i] = -1; dp[0] = 1; for (int i = 0; i < m; i++) { var x = ri - 1; var y = ri - 1; g[x] |= 1 << y; rg[y] |= 1 << x; } var C = new int[1 << n, n]; for (int i = 0; i < 1 << n; i++) for (int j = 0; j < n; j++) { C[i, j] = (1 << PopCount(g[j] & i)) - 1; C[i, j] *= 1 << PopCount(rg[j] & i); } const long MOD = (long)1e9 + 7; Func<int, long> f = null; f = (mask) => { if (dp[mask] >= 0) return dp[mask]; long ret = 0; for (int sub = mask; sub > 0; sub = (sub - 1) & mask) { if ((sub & 3) == 3) continue; var rem = mask ^ sub; var ok = true; long pat = 1; for (int i = 0; i < n; i++) { if ((mask >> i & 1) == 1) continue; pat = (pat * C[sub, i]) % MOD; } if (ok) ret = (ret + pat * f(rem)) % MOD; } return dp[mask] = ret; }; IO.Printer.Out.WriteLine(f((1 << n) - 1)); } int PopCount(int x) { var ret = 0; while (x != 0) { ret += x & 1; x /= 2; } return ret; } //* int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); char rc => sc.Char(); [System.Diagnostics.Conditional("DEBUG")] void put(params object[] a) => Debug.WriteLine(string.Join(" ", a)); //*/ public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { public static string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } public static string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } public static void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer: StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { } public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (; ; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion
Submission Info
Submission Time | |
---|---|
Task | F - Games on DAG |
User | camypaper |
Language | C# (Mono 4.6.2.0) |
Score | 1600 |
Code Size | 7527 Byte |
Status | AC |
Exec Time | 1450 ms |
Memory | 13252 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 | 20 ms | 11092 KB |
0_01.txt | AC | 20 ms | 9044 KB |
0_02.txt | AC | 20 ms | 11092 KB |
0_03.txt | AC | 21 ms | 9044 KB |
1_00.txt | AC | 20 ms | 11092 KB |
1_01.txt | AC | 1424 ms | 13024 KB |
1_02.txt | AC | 1424 ms | 13024 KB |
1_03.txt | AC | 1439 ms | 11104 KB |
1_04.txt | AC | 1436 ms | 13152 KB |
1_05.txt | AC | 1438 ms | 11104 KB |
1_06.txt | AC | 1438 ms | 13152 KB |
1_07.txt | AC | 1450 ms | 11104 KB |
1_08.txt | AC | 1440 ms | 11104 KB |
1_09.txt | AC | 1436 ms | 13152 KB |
1_10.txt | AC | 1439 ms | 11204 KB |
1_11.txt | AC | 1435 ms | 13152 KB |
1_12.txt | AC | 1437 ms | 13152 KB |
1_13.txt | AC | 1438 ms | 13152 KB |
1_14.txt | AC | 1438 ms | 13152 KB |
1_15.txt | AC | 1436 ms | 11104 KB |
1_16.txt | AC | 1436 ms | 11104 KB |
1_17.txt | AC | 1439 ms | 11104 KB |
1_18.txt | AC | 1439 ms | 13152 KB |
1_19.txt | AC | 1434 ms | 11104 KB |
1_20.txt | AC | 1432 ms | 13152 KB |
1_21.txt | AC | 24 ms | 9108 KB |
1_22.txt | AC | 1435 ms | 13152 KB |
1_23.txt | AC | 1434 ms | 13152 KB |
1_24.txt | AC | 462 ms | 9952 KB |
1_25.txt | AC | 22 ms | 11192 KB |
1_26.txt | AC | 1435 ms | 13252 KB |
1_27.txt | AC | 64 ms | 11108 KB |
1_28.txt | AC | 1426 ms | 13152 KB |
1_29.txt | AC | 159 ms | 11360 KB |
1_30.txt | AC | 63 ms | 11236 KB |
1_31.txt | AC | 1438 ms | 13152 KB |
1_32.txt | AC | 159 ms | 11360 KB |
1_33.txt | AC | 64 ms | 11108 KB |
1_34.txt | AC | 463 ms | 12000 KB |
1_35.txt | AC | 159 ms | 11360 KB |