Beispiel #1
0
 public static void Solve()
 {
     var(Ax, Ay, Bx, By) = Scanner.Scan <long, long, long, long>();
     var N = Scanner.Scan <int>();
     var V = new (long X, long Y)[N];
Beispiel #2
0
 public static void Solve()
 {
     var(AB, BC, CA) = Scanner.Scan <int, int, int>();
     Console.WriteLine(AB * BC / 2);
 }
Beispiel #3
0
 public static void Solve()
 {
     var(T, X) = Scanner.Scan <double, double>();
     Console.WriteLine(T / X);
 }
Beispiel #4
0
 public static void Solve()
 {
     var N = Scanner.Scan <int>();
     var A = Scanner.ScanEnumerable <int>().Select(x => x - 1).ToArray();
     var G = new List <int> [N].Select(x => new List <int>()).ToArray();
 }
Beispiel #5
0
 public static void Solve()
 {
     var N = Scanner.Scan <int>();
     var A = Scanner.ScanEnumerable <int>().ToArray();
     var B = Scanner.ScanEnumerable <int>().ToArray();
 }
Beispiel #6
0
 public static void Solve()
 {
     var(A, B) = Scanner.Scan <int, int>();
     Console.WriteLine(A <= 8 && B <= 8 ? "Yay!" : ":(");
 }
Beispiel #7
0
 public static void Solve()
 {
     var(N, W) = Scanner.Scan <int, int>();
     Console.WriteLine(N - 1);
 }
Beispiel #8
0
 public static void Solve()
 {
     var(N, W) = Scanner.Scan <int, int>();
     var X = new (int W, int V)[N];
Beispiel #9
0
        public static void Solve()
        {
            var N = Scanner.Scan <int>();

            Console.WriteLine((N + 1) / 2);
        }
Beispiel #10
0
 public static void Solve()
 {
     var N = Scanner.Scan <int>();
     var P = new (int X, int Y, int Z)[N];
Beispiel #11
0
 public static void Solve()
 {
     var S      = Scanner.Scan <string>();
     var answer = S + (S[^ 1] == 's' ? "es" : "s");
Beispiel #12
0
 public static void Solve()
 {
     var(A, B) = Scanner.Scan <int, int>();
     (A, B)    = (B, A);
     Console.WriteLine($"{A} {B}");
 }
Beispiel #13
0
 public static void Solve()
 {
     var(N, K) = Scanner.Scan <int, int>();
     var LR = new (int L, int R)[K];
Beispiel #14
0
        public static void Solve()
        {
            var N = Scanner.Scan <int>();
            var W = Scanner.ScanEnumerable <string>().ToArray();

            W[^ 1] = W[^ 1].Remove(W[^ 1].Length - 1);
Beispiel #15
0
        public static void Solve()
        {
            var(N, M) = Scanner.Scan <int, int>();
            var G = new List <int> [N].Select(x => new List <int>()).ToArray();

            for (var i = 0; i < M; i++)
            {
                var(a, b) = Scanner.Scan <int, int>();
                a--; b--;
                G[a].Add(b);
                G[b].Add(a);
            }

            var used  = new bool[N];
            var color = new int[N];
            var list  = new List <int>();

            void Dfs1(int u)
            {
                used[u] = true;
                list.Add(u);
                foreach (var v in G[u])
                {
                    if (!used[v])
                    {
                        Dfs1(v);
                    }
                }
            }

            long Dfs2(int idx)
            {
                var u = list[idx];

                foreach (var v in G[u])
                {
                    if (color[u] == color[v])
                    {
                        return(0);
                    }
                }

                if (idx == list.Count - 1)
                {
                    return(1);
                }

                var w   = list[idx + 1];
                var sum = 0L;

                for (var c = 0; c < 3; c++)
                {
                    color[w] = c;
                    sum     += Dfs2(idx + 1);
                }

                color[w] = -1;
                return(sum);
            }

            var answer = 1L;

            for (var u = 0; u < N; u++)
            {
                if (used[u])
                {
                    continue;
                }

                list.Clear();
                Dfs1(u);
                Array.Fill(color, -1);
                color[u] = 0;
                answer  *= Dfs2(0) * 3;
            }

            Console.WriteLine(answer);
        }
Beispiel #16
0
 public static void Solve()
 {
     var(X, T) = Scanner.Scan <int, int>();
     Console.WriteLine(Math.Max(0, X - T));
 }
Beispiel #17
0
 public static void Solve()
 {
     var(N, M) = Scanner.Scan <int, int>();
     var X = new (int a, int b)[N];
Beispiel #18
0
        public static void Solve()
        {
            var N = Scanner.Scan <int>();
            var A = Scanner.ScanEnumerable <long>().ToArray();
            var B = Scanner.ScanEnumerable <long>().ToArray();

            bool F(IEnumerable <long> a, IEnumerable <long> b) => a.Zip(b).All(x => x.First == x.Second);

            void Swap <T>(T[] array, int idx)
            => (array[idx], array[idx + 1], array[idx + 2]) = (array[idx + 2], array[idx], array[idx + 1]);

            if (N == 3)
            {
                for (var k = 0; k < 3; k++)
                {
                    if (F(A, B))
                    {
                        Console.WriteLine("Yes");
                        return;
                    }

                    Swap(A, 0);
                }

                Console.WriteLine("No");
                return;
            }

            for (var i = 0; i + 3 < N; i++)
            {
                var idx = Array.IndexOf(A, B[i], i);
                if (idx == -1)
                {
                    Console.WriteLine("No");
                    return;
                }

                for (var j = idx; j - 2 >= i; j -= 2)
                {
                    Swap(A, j - 2);
                }

                while (A[i] != B[i])
                {
                    Swap(A, i);
                }
            }

            long Encode(long[] array)
            {
                long result = 0;

                foreach (var v in array)
                {
                    result *= 10000;
                    result += v;
                }

                return(result);
            }

            long[] Decode(long v)
            {
                var result = new long[4];

                for (var i = 3; i >= 0; i--)
                {
                    result[i] = v % 10000;
                    v        /= 10000;
                }

                return(result);
            }

            var C = A[^ 4..];
Beispiel #19
0
        public static void Solve()
        {
            var(N, M, Q) = Scanner.Scan <int, int, int>();
            var G = new List <Node> [N].Select(x => new List <Node>()).ToArray();

            for (var i = 0; i < M; i++)
            {
                var(a, b, c) = Scanner.Scan <int, int, int>();
                a--; b--;
                G[a].Add(new Node(b, c));
                G[b].Add(new Node(a, c));
            }
            for (var i = 0; i < N; i++)
            {
                G[i].Sort((x, y) => x.Cost.CompareTo(y.Cost));
            }

            var QG = G.Select(x => new Queue <Node>(x)).ToArray();
            var X  = Scanner.ScanEnumerable <long>().ToArray();

            var queue = new Queue <Data>();

            queue.Enqueue(new Data(0, 0));
            var used = new bool[N];

            used[0] = true;
            var answer = new int[Q + 1];

            answer[0] = 1;

            while (queue.Count > 0)
            {
                var u = queue.Dequeue();
                if (u.Day >= Q)
                {
                    break;
                }
                var nd  = u.Day + 1;
                var que = QG[u.ID];
                while (que.Count > 0)
                {
                    var v = que.Peek();
                    if (used[v.ID])
                    {
                        que.Dequeue();
                        continue;
                    }

                    if (v.Cost > X[u.Day])
                    {
                        break;
                    }
                    que.Dequeue();
                    used[v.ID] = true;
                    answer[nd]++;
                    queue.Enqueue(new Data(v.ID, nd));
                }

                if (que.Count > 0)
                {
                    queue.Enqueue(new Data(u.ID, nd));
                }
            }

            for (var i = 1; i <= Q; i++)
            {
                answer[i] += answer[i - 1];
            }

            Console.WriteLine(string.Join("\n", answer.Skip(1)));
        }
Beispiel #20
0
 public static void Solve()
 {
     var(N, M, T) = Scanner.Scan <int, int, long>();
     var A  = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
     var G1 = new List <(int, long)> [N].Select(x => new List <(int, long)>()).ToArray();
Beispiel #21
0
 public static void Solve()
 {
     var N      = Scanner.Scan <int>();
     var S      = Scanner.Scan <string>();
     var answer = S[^ 1];
Beispiel #22
0
 public static void Solve()
 {
     var N = Scanner.Scan <int>();
     var P = new (long X, long Y)[N];
Beispiel #23
0
 public static void Solve()
 {
     var N = Scanner.Scan <int>();
     var T = new (int D, int C, long S)[N];
Beispiel #24
0
 public static void Solve()
 {
     var H1 = Scanner.Scan<int>();
     var H2 = Scanner.Scan<int>();
     Console.WriteLine(H1 - H2);
 }
Beispiel #25
0
 public static void Solve()
 {
     var(N, M, Q) = Scanner.Scan <int, int, int>();
     var Query = new (int A, int B, int C, int D)[Q];
Beispiel #26
0
        public static void Solve()
        {
            var N = Scanner.Scan <int>();

            var S1 = "";
            var S2 = "";

            while (true)
            {
                var ok = false;
                for (var s = 0; s < 1 << 2 && !ok; s++)
                {
                    Console.WriteLine(S1 + ((s & 1) == 0 ? "." : "#"));
                    Console.WriteLine(S2 + ((s & 2) == 0 ? "." : "#"));
                    var result = Scanner.Scan <string>();
                    if (result == "end")
                    {
                        return;
                    }
                    if (result == "T")
                    {
                        ok = true;
                        S1 = S1 + ((s & 1) == 0 ? "." : "#");
                        S2 = S2 + ((s & 2) == 0 ? "." : "#");
                        break;
                    }
                }

                if (!ok)
                {
                    break;
                }
            }

            while (true)
            {
                var ok = false;
                for (var s = 0; s < 1 << 2 && !ok; s++)
                {
                    Console.WriteLine(((s & 1) == 0 ? "." : "#") + S1);
                    Console.WriteLine(((s & 2) == 0 ? "." : "#") + S2);
                    var result = Scanner.Scan <string>();
                    if (result == "end")
                    {
                        return;
                    }
                    if (result == "T")
                    {
                        ok = true;
                        S1 = ((s & 1) == 0 ? "." : "#") + S1;
                        S2 = ((s & 2) == 0 ? "." : "#") + S2;
                        break;
                    }
                }

                if (!ok)
                {
                    break;
                }
            }
        }
Beispiel #27
0
        public static void Solve()
        {
            var(N, M, K) = Scanner.Scan <int, int, int>();
            var A = Scanner.ScanEnumerable <long>().ToList();
            var B = Scanner.ScanEnumerable <long>().ToList();

            A.Reverse();
            B.Reverse();
            for (var i = 0; i < A.Count; i++)
            {
                var x = A[i] / K;
                if (i + 1 < A.Count)
                {
                    A[i + 1] += x;
                }
                else if (x != 0)
                {
                    A.Add(x);
                }

                A[i] %= K;
            }

            for (var i = 0; i < B.Count; i++)
            {
                var x = B[i] / K;
                if (i + 1 < B.Count)
                {
                    B[i + 1] += x;
                }
                else if (x != 0)
                {
                    B.Add(x);
                }

                B[i] %= K;
            }

            if (A.Count != B.Count)
            {
                if (A.Count < B.Count)
                {
                    Console.WriteLine("X");
                }
                else
                {
                    Console.WriteLine("Y");
                }
                return;
            }

            A.Reverse();
            B.Reverse();
            for (var i = 0; i < A.Count; i++)
            {
                if (A[i] == B[i])
                {
                    continue;
                }
                if (A[i] < B[i])
                {
                    Console.WriteLine("X");
                }
                else
                {
                    Console.WriteLine("Y");
                }
                return;
            }

            Console.WriteLine("Same");
        }
Beispiel #28
0
 public static void Solve()
 {
     var N      = Scanner.Scan <int>();
     var LR     = new (int L, int R)[N];
Beispiel #29
0
 public static void Solve()
 {
     var(N, T) = Scanner.Scan <int, int>();
     var AB = new (int A, int B)[N];
Beispiel #30
0
        public static void Solve()
        {
            var S = Scanner.Scan <string>();

            Console.WriteLine($"{S[..4]} {S[4..]}");