Exemplo n.º 1
0
    public void Solve()
    {
        int N   = Reader.Int();
        var E   = EdgeRead(N);
        var deg = E.Select(e => (long)e.Length).ToArray();
        var set = new AVLTreeSortedSet();

        for (int i = 0; i < N; i++)
        {
            set.Add((deg[i] << 32) + i);
        }

        Action <int> RemoveV = a =>
        {
            set.Remove((deg[a] << 32) + a);
            deg[a] = 0;
            foreach (int b in E[a])
            {
                if (deg[b] > 0)
                {
                    set.Remove((deg[b] << 32) + b);
                    deg[b]--;
                    set.Add((deg[b] << 32) + b);
                }
            }
        };

        for (; set.Count > 1;)
        {
            int a = (int)set[0];
            if (deg[a] == 0)
            {
                break;
            }
            Debug.Assert(deg[a] == 1);
            int b = Array.Find(E[a], x => deg[x] > 0);
            RemoveV(a);
            RemoveV(b);
        }

        Console.WriteLine(set.Count > 0 && (set[0] >> 32) == 0 ? "First" : "Second");
    }
Exemplo n.º 2
0
    public void Solve()
    {
        int H = Reader.Int(), W = Reader.Int(), N = Reader.Int();
        var sw    = Stopwatch.StartNew();
        var table = Reader.IntTable(N);
        var set   = new AVLTreeSortedSet(N * 9);
        var black = new AVLTreeSortedSet(N);
        var ans   = new long[10];

        ans[0] = (long)(H - 2) * (W - 2);
        Func <int, int, bool> IsInside = (r, c) => r >= 0 && r < H && c >= 0 && c < W;

        foreach (var t in table)
        {
            black.Add(--t[0] * Big + --t[1]);
            for (int dr = -2; dr <= 0; dr++)
            {
                for (int dc = -2; dc <= 0; dc++)
                {
                    if (IsInside(t[0] + dr, t[1] + dc))
                    {
                        set.Add((t[0] + dr) * Big + t[1] + dc);
                    }
                }
            }
        }
        long add = sw.ElapsedMilliseconds;

        foreach (long mask in set.ToArray())
        {
            long r = mask / Big, c = mask % Big;
            if (r + 3 <= H && c + 3 <= W)
            {
                int count = 0;
                for (int dr = 0; dr < 3; dr++)
                {
                    for (int dc = 0; dc < 3; dc++)
                    {
                        if (black.Contains((r + dr) * Big + c + dc))
                        {
                            count++;
                        }
                    }
                }
                ans[0]--;
                ans[count]++;
            }
        }
        Console.WriteLine(string.Join("\n", ans));
        //Console.WriteLine("Max:" + set.MaxDepth);
        //Console.WriteLine("Rotate:" + set.RotateCount);
        //Console.WriteLine("Add:   " + add + "ms");
    }