Beispiel #1
0
        public static void Solve()
        {
            var N      = Scanner.Scan <int>();
            var answer = new int[N];

            for (var x = 1; x *x <= N; x++)
            {
                for (var y = 1; y *y <= N; y++)
                {
                    if (x * x + y * y + x * y > N)
                    {
                        break;
                    }
                    for (var z = 1; z *z <= N; z++)
                    {
                        var f = x * x + y * y + z * z + x * y + y * z + z * x;
                        if (f > N)
                        {
                            break;
                        }
                        answer[f - 1]++;
                    }
                }
            }

            Printer.Print1D(answer, "\n");
        }
Beispiel #2
0
        public static void Solve()
        {
            var(N, K, S) = Scanner.Scan <int, int, int>();
            var answer = new int[N];

            Array.Fill(answer, S == (int)1e9 ? 1 : S + 1);
            Array.Fill(answer, S, 0, K);

            Printer.Print1D(answer, " ");
        }
Beispiel #3
0
        public static void Solve()
        {
            var N   = Scanner.Scan <int>();
            var rep = N / 9 + 1;
            var dig = N % 9;

            if (dig == 0)
            {
                dig = 9;
                rep--;
            }
            Printer.Print1D(Enumerable.Repeat(dig, rep));
        }
Beispiel #4
0
        public static void Solve()
        {
            var map = Enumerable.Repeat(-1, char.MaxValue).ToArray();

            map['b'] = map['c'] = 1;
            map['d'] = map['w'] = 2;
            map['t'] = map['j'] = 3;
            map['f'] = map['q'] = 4;
            map['l'] = map['v'] = 5;
            map['s'] = map['x'] = 6;
            map['p'] = map['m'] = 7;
            map['h'] = map['k'] = 8;
            map['n'] = map['g'] = 9;
            map['z'] = map['r'] = 0;

            var N      = Scanner.Scan <int>();
            var S      = Scanner.ScanEnumerable <string>().ToArray();
            var answer = new List <string>();

            foreach (var s in S)
            {
                var builder = new StringBuilder();
                foreach (var c in s)
                {
                    var num = map[char.ToLower(c)];
                    if (num >= 0)
                    {
                        builder.Append(num.ToString());
                    }
                }
                if (builder.Length > 0)
                {
                    answer.Add(builder.ToString());
                }
            }
            if (answer.Count > 0)
            {
                Printer.Print1D(answer, " ");
            }
            else
            {
                Console.WriteLine();
            }
        }
Beispiel #5
0
        public static void Solve()
        {
            var(N, M, S) = Scanner.Scan <int, 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--;
                if (a > b)
                {
                    (a, b) = (b, a);
                }
                G[a].Add(b);
            }

            var dsu = new DisjointSetUnion(N);

            for (var u = N - 1; u >= S; u--)
            {
                foreach (var v in G[u])
                {
                    dsu.Merge(u, v);
                }
            }

            var answer = new List <int>();

            answer.Add(S);
            S--;
            for (var u = S - 1; u >= 0; u--)
            {
                foreach (var v in G[u])
                {
                    dsu.Merge(u, v);
                }
                if (dsu.IsSame(S, u))
                {
                    answer.Add(u + 1);
                }
            }
            answer.Reverse();
            Printer.Print1D(answer, "\n");
        }
Beispiel #6
0
        public static void Solve()
        {
            var S = Scanner.ScanEnumerable <string>().ToArray();
            var T = new List <string>();

            foreach (var s in S)
            {
                switch (s)
                {
                case "Left": T.Add("<"); break;

                case "Right": T.Add(">"); break;

                case "AtCoder": T.Add("A"); break;

                default: break;
                }
            }

            Printer.Print1D(T, " ");
        }
Beispiel #7
0
        public static void Solve()
        {
            var N = Scanner.Scan <int>();
            var G = new List <int> [N].Select(x => new List <int>()).ToArray();

            for (var a = 1; a < N; a++)
            {
                var b = Scanner.Scan <int>();
                G[a].Add(b);
                G[b].Add(a);
            }
            var dp = new int[N];

            int Dfs(int u, int p)
            {
                if (dp[u] > 0)
                {
                    return(dp[u]);
                }
                var c = 0;

                foreach (var v in G[u])
                {
                    if (v == p)
                    {
                        continue;
                    }
                    var cc = Dfs(v, u);
                    c    += cc;
                    dp[u] = Math.Max(dp[u], cc);
                }
                dp[u] = Math.Max(dp[u], N - 1 - c);
                return(c + 1);
            }

            Dfs(0, -1);

            Printer.Print1D(dp, "\n");
        }
Beispiel #8
0
        public static void Solve()
        {
            var B   = Scanner.ScanEnumerable <int>().ToArray();
            var N   = Scanner.Scan <int>();
            var A   = new string[N].Select(_ => Scanner.Scan <string>()).ToArray();
            var map = new int[10, 10];

            for (var i = 0; i < 10; i++)
            {
                for (var j = 0; j < 10; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    map[B[i], B[j]] = i < j ? -1 : 1;
                }
            }

            Array.Sort(A, (x, y) =>
            {
                var result = x.Length.CompareTo(y.Length);
                if (result != 0)
                {
                    return(result);
                }
                for (var i = 0; i < x.Length; i++)
                {
                    result = map[x[i] - '0', y[i] - '0'];
                    if (result != 0)
                    {
                        return(result);
                    }
                }
                return(0);
            });

            Printer.Print1D(A, "\n");
        }
Beispiel #9
0
        public static void Solve()
        {
            var N      = Scanner.Scan <int>();
            var answer = new int[6];

            for (var i = 0; i < N; i++)
            {
                var(max, min) = Scanner.Scan <double, double>();
                if (max >= 35)
                {
                    answer[0]++;
                }
                else if (max >= 30)
                {
                    answer[1]++;
                }
                else if (max >= 25)
                {
                    answer[2]++;
                }
                if (min >= 25)
                {
                    answer[3]++;
                }
                if (max >= 0 && min < 0)
                {
                    answer[4]++;
                }
                if (max < 0)
                {
                    answer[5]++;
                }
            }

            Printer.Print1D(answer, " ");
        }
Beispiel #10
0
        public static void Solve()
        {
            var N = Scanner.Scan <int>();
            var R = new List <int>();
            var B = new List <int>();

            for (var i = 0; i < N; i++)
            {
                var(x, c) = Scanner.Scan <int, char>();
                (c == 'R' ? R : B).Add(x);
            }

            R.Sort();
            B.Sort();

            if (R.Any())
            {
                Printer.Print1D(R, "\n");
            }
            if (B.Any())
            {
                Printer.Print1D(B, "\n");
            }
        }
Beispiel #11
0
        public static void Solve()
        {
            var N      = Scanner.Scan <int>();
            var answer = new List <string>();

            void Dfs(string str, char max)
            {
                if (str.Length == N)
                {
                    answer.Add(str);
                    return;
                }

                for (var c = 'a'; c < max; c++)
                {
                    Dfs(str + c, max);
                }
                Dfs(str + max, (char)(max + 1));
            }

            Dfs("", 'a');

            Printer.Print1D(answer, "\n");
        }