Submission #2859019


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(int N, int[] A)
        {
            var tuples = new Tuple<int, int>[N];
            for (int i = 0; i < N; ++i)
            {
                tuples[i] = new Tuple<int, int>(A[i], i);
            }
            Array.Sort(tuples);

            long sum = 0;
            var list = new SortedList<int, int>();
            list[-1] = 0;
            list[N] = 0;
            for (int i = 0; i < N; ++i)
            {
                int n = tuples[i].Item2;
                list[n] = 0;
                int j = list.IndexOfKey(n);
                int L = list.ElementAt(j - 1).Key;
                int R = list.ElementAt(j + 1).Key;
                sum += Math.BigMul(n - L, R - n) * tuples[i].Item1;
            }
            return sum;
        }

        static void Main(string[] args)
        {
            int N = ReadInt();
            int[] A = ReadInts();
            Console.WriteLine(Solve(N, A));
        }
    }
}

Submission Info

Submission Time
Task B - Minimum Sum
User M_Saito
Language C# (Mono 4.6.2.0)
Score 0
Code Size 1742 Byte
Status TLE
Exec Time 2108 ms
Memory 33244 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 7
TLE × 6
Set Name Test Cases
Sample example0, example1, example2
All corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 TLE 2108 ms 29532 KB
corner1 TLE 2108 ms 27100 KB
corner2 AC 26 ms 9428 KB
corner3 TLE 2108 ms 33244 KB
example0 AC 27 ms 11476 KB
example1 AC 27 ms 13524 KB
example2 AC 26 ms 9428 KB
maxrand0 TLE 2108 ms 27100 KB
maxrand1 TLE 2108 ms 27100 KB
maxrand2 TLE 2108 ms 27100 KB
rand0 AC 28 ms 11476 KB
rand1 AC 27 ms 11476 KB
rand2 AC 26 ms 9428 KB