Submission #45196083


Source Code Expand

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;

namespace Tasks;

public class E
{
    public static void Main()
    {
        using var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }

    public static void Solve()
    {
        var N = Scanner.Scan<int>();
        var A = Scanner.ScanEnumerable<int>().Select(x => x - 1).ToArray();
        var L = new long[N];
        var R = new long[N];

        foreach (var a in A) R[a]++;

        long answer = 0;
        long cum = 0;
        foreach (var a in A)
        {
            cum -= L[a] * R[a];
            answer += cum;
            R[a]--;
            L[a]++;
            cum += L[a] * R[a];
        }

        Console.WriteLine(answer);
    }

    public static class Scanner
    {
        public static T Scan<T>() where T : IConvertible => Convert<T>(ScanStringArray()[0]);
        public static (T1, T2) Scan<T1, T2>() where T1 : IConvertible where T2 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]));
        }
        public static (T1, T2, T3) Scan<T1, T2, T3>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]));
        }
        public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]));
        }
        public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]));
        }
        public static (T1, T2, T3, T4, T5, T6) Scan<T1, T2, T3, T4, T5, T6>() where T1 : IConvertible where T2 : IConvertible where T3 : IConvertible where T4 : IConvertible where T5 : IConvertible where T6 : IConvertible
        {
            var input = ScanStringArray();
            return (Convert<T1>(input[0]), Convert<T2>(input[1]), Convert<T3>(input[2]), Convert<T4>(input[3]), Convert<T5>(input[4]), Convert<T6>(input[5]));
        }
        public static IEnumerable<T> ScanEnumerable<T>() where T : IConvertible => ScanStringArray().Select(Convert<T>);
        private static string[] ScanStringArray()
        {
            var line = Console.ReadLine()?.Trim() ?? string.Empty;
            return string.IsNullOrEmpty(line) ? Array.Empty<string>() : line.Split(' ');
        }
        private static T Convert<T>(string value) where T : IConvertible => (T)System.Convert.ChangeType(value, typeof(T));
    }
}

Submission Info

Submission Time
Task E - Sandwiches
User AconCavy
Language C# 11.0 (.NET 7.0.7)
Score 450
Code Size 3256 Byte
Status AC
Exec Time 97 ms
Memory 60844 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 20
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 55 ms 26528 KiB
00_sample_02.txt AC 59 ms 26244 KiB
00_sample_03.txt AC 48 ms 26196 KiB
01_test_01.txt AC 53 ms 26372 KiB
01_test_02.txt AC 49 ms 26340 KiB
01_test_03.txt AC 97 ms 57160 KiB
01_test_04.txt AC 88 ms 57116 KiB
01_test_05.txt AC 93 ms 54272 KiB
01_test_06.txt AC 96 ms 56016 KiB
01_test_07.txt AC 85 ms 55644 KiB
01_test_08.txt AC 92 ms 56464 KiB
01_test_09.txt AC 87 ms 56836 KiB
01_test_10.txt AC 93 ms 56768 KiB
01_test_11.txt AC 86 ms 59796 KiB
01_test_12.txt AC 97 ms 59764 KiB
01_test_13.txt AC 94 ms 60796 KiB
01_test_14.txt AC 87 ms 60844 KiB
01_test_15.txt AC 91 ms 60584 KiB
01_test_16.txt AC 94 ms 55316 KiB
01_test_17.txt AC 78 ms 41548 KiB