Ejemplo n.º 1
0
    public static void PluralForm()
    {
        var s    = IOLibrary.ReadLine();
        var text = (s[s.Length - 1] != 's') ? "s" : "es";

        Console.WriteLine(s + text);
    }
Ejemplo n.º 2
0
 public static ModInt[] ReadModIntArray(int mod)
 {
     ModInt.Init(mod);
     return(IOLibrary.ReadStringArray()
            .Select(item => (ModInt)int.Parse(item))
            .ToArray());
 }
Ejemplo n.º 3
0
    public static void PlacingMarbles()
    {
        var s   = IOLibrary.ReadLine();
        var ans = s.Count(c => c == '1');

        Console.WriteLine(ans);
    }
Ejemplo n.º 4
0
    public static void ThreePointShot()
    {
        var(X, Y) = IOLibrary.ReadInt2();
        var sub = Math.Abs(X - Y);

        Console.WriteLine(IOLibrary.YesOrNo(sub < 3));
    }
Ejemplo n.º 5
0
    public static void MexBoxes()
    {
        var(N, K) = IOLibrary.ReadLong2();
        var a       = IOLibrary.ReadLongArray();
        var sortedA = a.Sort().GroupBy(item => item);

        var sum = 0L;

        var num    = -1L;
        var boxNum = K;

        foreach (var ball in sortedA)
        {
            if (ball.Key == num + 1)
            {
                //iに書き換える箱の個数
                var x = Math.Min(ball.Count(), boxNum);
                sum += x;

                boxNum = x;
                num    = ball.Key;
            }
        }

        Console.WriteLine(sum);
    }
Ejemplo n.º 6
0
    public static void HeavyRotation()
    {
        var N     = IOLibrary.ReadInt();
        var color = (N % 2 == 0) ? "White" : "Black";

        Console.WriteLine(color);
    }
Ejemplo n.º 7
0
    public static void Box()
    {
        var(N, A, B) = IOLibrary.ReadInt3();
        var num = N - A + B;

        Console.WriteLine(num);
    }
Ejemplo n.º 8
0
    public static void GoodDistance()
    {
        var(N, D) = IOLibrary.ReadInt2();
        var X = IOLibrary.ReadInt2DArray(N, D);

        var count = 0L;

        foreach (var pair in MathLibrary.GetCombinationIndexCollection(N, 2))
        {
            var i = pair[0];
            var j = pair[1];

            var squareLength = 0L;
            for (var index = 0; index < D; index++)
            {
                var dx = X[i, index] - X[j, index];
                squareLength += dx * dx;
            }
            var length = (int)Math.Sqrt(squareLength);
            if (length * length == squareLength)
            {
                count++;
            }
        }

        Console.WriteLine(count);
    }
Ejemplo n.º 9
0
    public static void SnukePrime()
    {
        var(N, C) = IOLibrary.ReadLong2();

        var dic = new SortedDictionary <long, long>();

        for (var i = 0L; i < N; i++)
        {
            var(a, b, c) = IOLibrary.ReadLong3();
            if (dic.ContainsKey(a))
            {
                dic[a] += c;
            }
            else
            {
                dic.Add(a, c);
            }

            var afterB = b + 1;
            if (dic.ContainsKey(afterB))
            {
                dic[afterB] -= c;
            }
            else
            {
                dic.Add(afterB, -c);
            }
        }

        //集計
        var array = dic.Values.ToArray();
        var sum   = 0L;

        var startDay = 1L;
        var prevCost = 0L;

        var isFirst = true;

        foreach (var keyValue in dic)
        {
            if (isFirst)
            {
                startDay = keyValue.Key;
                prevCost = keyValue.Value;
                isFirst  = false;
            }
            else
            {
                var days = keyValue.Key - startDay;

                var minCost = Math.Min(prevCost, C);
                sum += minCost * days;

                startDay  = keyValue.Key;
                prevCost += keyValue.Value;;
            }
        }

        Console.WriteLine(sum);
    }
Ejemplo n.º 10
0
    public static void Log()
    {
        var n    = IOLibrary.ReadLong();
        var cost = n;

        //n+1の分割
        var ng = n + 1;
        var ok = 0L;

        //1+・・・+k<=n+1を満たす最大のkを求める
        while (Math.Abs(ok - ng) > 1)
        {
            var middle = ok + (ng - ok) / 2;
            //1からkまでの和
            var sum = middle * (middle + 1) / 2;
            if (sum <= n + 1)
            {
                ok = middle;
            }
            else
            {
                ng = middle;
            }
        }

        var dividedNum = ok;

        cost = cost - dividedNum + 1;
        Console.WriteLine(cost);
    }
Ejemplo n.º 11
0
    public static void LargeRPSTournament()
    {
        var(n, k) = IOLibrary.ReadInt2();
        var s         = IOLibrary.ReadLine();
        var queue     = new Queue <char>(s);
        var gameCount = 0;

        while (k > 0)
        {
            queue = ARC100.TwiceQueue(queue);

            var queueNum = queue.Count;
            while (queueNum > 0)
            {
                var a = queue.Dequeue();
                var b = queue.Dequeue();
                queueNum -= 2;
                var winner = ARC100.Judge(a, b);
                gameCount++;
                queue.Enqueue(winner);
            }

            if (gameCount >= k)
            {
                //第i回戦終了
                k--;
                gameCount = 0;
            }
        }

        var champion = queue.Dequeue();

        Console.WriteLine(champion);
    }
Ejemplo n.º 12
0
    public static void ATCoder()
    {
        var S = IOLibrary.ReadLine();

        var str = "ACGT";

        var ans   = 0;
        var count = 0;

        foreach (var s in S)
        {
            if (str.Contains(s))
            {
                count++;
            }
            else
            {
                count = 0;
            }

            ans = Math.Max(ans, count);
        }

        Console.WriteLine(ans);
    }
Ejemplo n.º 13
0
    public static void GoToSchool()
    {
        var N = IOLibrary.ReadInt();
        var A = IOLibrary.ReadIntArray()
                .Select((content, index) => new
        {
            Content = content,
            Index   = index,
        })
                .ToArray();

        Array.Sort(A,
                   (x, y) =>
        {
            if (x.Content == y.Content)
            {
                return(0);
            }
            else if (x.Content < y.Content)
            {
                return(-1);
            }
            else
            {
                return(1);
            }
        });

        var ans = string.Join(" ", A.Select(a => a.Index + 1));

        Console.WriteLine(ans);
    }
Ejemplo n.º 14
0
    public static void ReplacingInteger()
    {
        var(N, K) = IOLibrary.ReadLong2();
        var remainder = N % K;

        Console.WriteLine(Math.Min(remainder, K - remainder));
    }
Ejemplo n.º 15
0
    public static void QueenOnGrid()
    {
        var(H, W) = IOLibrary.ReadInt2();
        var S = IOLibrary.ReadStringArray(H);

        var ans = new ModInt[H, W];

        //初期化
        ans[0, 0] = 1;
        for (var row = 1; row < H; row++)
        {
            if (S[row][0] != '#')
            {
                if (row == 1)
                {
                    ans[row, 0] = 1;
                }
                else
                {
                    ans[row, 0] = ans[row - 1, 0] * 2;
                }
            }
        }

        for (var col = 1; col < W; col++)
        {
            if (S[0][col] != '#')
            {
                if (col == 1)
                {
                    ans[0, col] = 1;
                }
                else
                {
                    ans[0, col] = ans[0, col - 1] * 2;
                }
            }
        }

        var horizontalSum = new ModInt[H, W];
        var verticlSum    = new ModInt[H, W];
        var diagonalSum   = new ModInt[H, W];

        //集計
        for (var row = 1; row < H; row++)
        {
            for (var col = 1; col < W; col++)
            {
                if (S[row][col] != '#')
                {
                    horizontalSum[row, col] = horizontalSum[row - 1, col] + ans[row - 1, col];
                    verticlSum[row, col]    = verticlSum[row, col - 1] + ans[row, col - 1];
                    diagonalSum[row, col]   = diagonalSum[row - 1, col - 1] + ans[row - 1, col - 1];
                    ans[row, col]           = horizontalSum[row, col] + verticlSum[row, col] + diagonalSum[row, col];
                }
            }
        }

        Console.WriteLine(ans[H - 1, W - 1]);
    }
Ejemplo n.º 16
0
    public static void GentlePairs()
    {
        var N      = IOLibrary.ReadInt();
        var points = IOLibrary.ReadInt2DArray(N);

        var ans = 0;

        for (var i = 0; i < N; i++)
        {
            for (var j = i + 1; j < N; j++)
            {
                if (i < j)
                {
                    var pointI = points[i];
                    var pointJ = points[j];

                    var dx = Math.Abs(pointI[0] - pointJ[0]);
                    var dy = Math.Abs(pointI[1] - pointJ[1]);
                    if (dx >= dy)
                    {
                        ans++;
                    }
                }
            }
        }

        Console.WriteLine(ans);
    }
Ejemplo n.º 17
0
    public static void Twiblr()
    {
        var(A, B) = IOLibrary.ReadLong2();
        var diff = 2 * A + 100 - B;

        Console.WriteLine(diff);
    }
Ejemplo n.º 18
0
    public static void ChooseMe()
    {
        var N = IOLibrary.ReadInt();

        var sub     = 0L;
        var subList = new List <long>();

        for (var i = 0; i < N; i++)
        {
            var(A, B) = IOLibrary.ReadLong2();
            sub      -= A;
            var sum = 2 * A + B;
            subList.Add(sum);
        }
        subList.Sort();

        var ans = 0;

        while (sub <= 0)
        {
            sub += subList.Last();
            subList.RemoveAt(subList.Count - 1);
            ans++;
        }

        Console.WriteLine($"{ans}");
    }
Ejemplo n.º 19
0
    public static void Collinearity()
    {
        var N      = IOLibrary.ReadInt();
        var pArray = new Point[N];

        for (var i = 0; i < N; i++)
        {
            var(x, y) = IOLibrary.ReadInt2();
            var p = new Point(x, y);
            pArray[i] = p;
        }

        foreach (var indexArray in MathLibrary.GetCombinationIndexCollection(N, 3))
        {
            var p0   = pArray[indexArray[0]];
            var p1   = pArray[indexArray[1]];
            var p2   = pArray[indexArray[2]];
            var area = Point.CalcTriangleArea(p0 - p1, p0 - p2);
            if (area == 0)
            {
                Console.WriteLine(IOLibrary.YesOrNo(true));
                return;
            }
        }

        Console.WriteLine(IOLibrary.YesOrNo(false));
    }
Ejemplo n.º 20
0
    public static void BlockOnGrid()
    {
        var(H, W) = IOLibrary.ReadInt2();

        var min = int.MaxValue;

        var A = new int[H][];

        for (var row = 0; row < H; row++)
        {
            A[row] = IOLibrary.ReadIntArray();

            for (var col = 0; col < A[row].Length; col++)
            {
                var num = A[row][col];
                if (num < min)
                {
                    min = num;
                }
            }
        }

        var sum = 0L;

        for (var row = 0; row < H; row++)
        {
            for (var col = 0; col < W; col++)
            {
                sum += A[row][col] - min;
            }
        }

        Console.WriteLine(sum);
    }
Ejemplo n.º 21
0
    public static void Creampuff()
    {
        var N    = IOLibrary.ReadLong();
        var list = MathLibrary.GetDivisorSortedList(N);

        IOLibrary.OutputList(list);
    }
Ejemplo n.º 22
0
    public static void UnluckySeven()
    {
        var N = IOLibrary.ReadInt();

        var count = 0;

        for (var num = 1; num <= N; num++)
        {
            //10進数
            if (num.ToString().Contains("7"))
            {
                count++;
            }
            else
            {
                //8進数
                if (num.ToOct().Contains("7"))
                {
                    count++;
                }
            }
        }

        var ans = N - count;

        Console.WriteLine(ans);
    }
Ejemplo n.º 23
0
    public static void ReversibleCards()
    {
        var N = IOLibrary.ReadInt();

        var abArray = IOLibrary.ReadInt2DArray(N);

        var max = 400000;
        var sum = new int[max];

        var ans = 0;

        for (var i = 0; i < N; i++)
        {
            var(a, b) = IOLibrary.ReadInt2();

            if (sum[a] == 0)
            {
                ans++;
            }
            else if (sum[b] == 0)
            {
                ans++;
            }
        }

        Console.WriteLine(ans);
    }
Ejemplo n.º 24
0
    public static void Billiard()
    {
        var(Sx, Sy, Gx, Gy) = IOLibrary.ReadLong4();
        var y0 = (Sx * Gy + Sy * Gx) / (Sy + Gy);

        Console.WriteLine(y0);
    }
Ejemplo n.º 25
0
    public static void TwoSequences2()
    {
        var N = IOLibrary.ReadInt();
        var a = IOLibrary.ReadLongArray();
        var b = IOLibrary.ReadLongArray();

        var maxA = a[0];
        var maxC = a[0] * b[0];

        for (var j = 0; j < N; j++)
        {
            for (var i = Math.Max(0, j - 1); i <= j; i++)
            {
                if (a[i] > maxA)
                {
                    maxA = a[j];
                }
            }

            var c = maxA * b[j];
            if (c > maxC)
            {
                maxC = c;
            }

            Console.WriteLine(maxC);
        }
    }
Ejemplo n.º 26
0
    public static void Travel()
    {
        var(N, K) = IOLibrary.ReadInt2();
        var T = IOLibrary.ReadInt2DArray(N);

        var indexList = MathLibrary.GetPermutationIndex(Enumerable.Range(1, N - 1).ToArray());
        var count     = 0;

        foreach (var index in indexList)
        {
            var sumTime = 0;

            //末尾に終点0を追加
            var newIndexList = index.Concat(new int[] { 0 });

            var beforePoint = 0;

            foreach (var currentIndex in newIndexList)
            {
                var time = T[beforePoint][currentIndex];
                sumTime    += time;
                beforePoint = currentIndex;
            }

            if (sumTime == K)
            {
                count++;
            }
        }

        Console.WriteLine(count);
    }
Ejemplo n.º 27
0
    public static void Lottery()
    {
        var n = IOLibrary.ReadInt();
        var m = IOLibrary.ReadInt();
        var x = IOLibrary.ReadIntArray().Sort().ToArray();

        var cdArray = new int[n * n];

        for (var c = 0; c < n; c++)
        {
            for (var d = 0; d < n; d++)
            {
                cdArray[c * d + d] = c + d;
            }
        }

        for (var a = 0; a < n; a++)
        {
            for (var b = 0; b < n; b++)
            {
                var xd = m - x[a] + x[b];
                var d  = x.BinarySearch(xd);
                if (d >= 0)
                {
                    Console.WriteLine(IOLibrary.YesOrNo(true));
                }
            }
        }

        Console.WriteLine(IOLibrary.YesOrNo(false));
    }
Ejemplo n.º 28
0
    public static void WaterHeater()
    {
        var(N, W) = IOLibrary.ReadLong2();

        var S = new long[N];
        var T = new long[N];
        var P = new long[N];

        for (var i = 0; i < N; i++)
        {
            (S[i], T[i], P[i]) = IOLibrary.ReadLong3();
        }

        var maxTime = T.Max();
        var table   = new long[maxTime + 2];

        for (var i = 0; i < N; i++)
        {
            table[S[i]] += P[i];
            table[T[i]] -= P[i];
        }

        //集計
        for (var i = 0; i < table.Length; i++)
        {
            table[i + 1] += table[i];
            if (table[i] > W)
            {
                Console.WriteLine(IOLibrary.YesOrNo(false));
                return;
            }
        }

        Console.WriteLine(IOLibrary.YesOrNo(true));
    }
Ejemplo n.º 29
0
    public static void Coins()
    {
        var A = IOLibrary.ReadInt();
        var B = IOLibrary.ReadInt();
        var C = IOLibrary.ReadInt();
        var X = IOLibrary.ReadInt();

        var count = 0;

        for (var a = 0; a <= A; a++)
        {
            for (var b = 0; b <= B; b++)
            {
                for (var c = 0; c <= C; c++)
                {
                    var total = 500 * a + 100 * b + 50 * c;
                    if (total == X)
                    {
                        count++;
                    }
                }
            }
        }
        Console.WriteLine(count);
    }
Ejemplo n.º 30
0
    public static void Alphabet()
    {
        var a   = IOLibrary.ReadLine();
        var ans = char.IsUpper(a[0]) ? "A" : "a";

        Console.WriteLine(ans);
    }