ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1196. History Exam

Почему TLE 8 ? Оптимизировал на сколько мог / Why TLE 8
Posted by Niks43rus 18 Apr 2017 22:58
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int count = 0, j, n, m, t, i;
            n = int.Parse(Console.ReadLine());
            int[] p_dat = new int[n];

            for (i = 0; i < n; i++)
            {
                p_dat[i] = int.Parse(Console.ReadLine());

            }
            m = int.Parse(Console.ReadLine());
            int[] s_dat = new int[m];
            for (i = 0; i < m; i++)
            {
                s_dat[i] = int.Parse(Console.ReadLine());
            }
            for (i = 0; i < n - 1; i++)
            {
                if (p_dat[i] == p_dat[i + 1])
                {
                    p_dat[i] = p_dat[i + 1];
                    i--;
                    n--;
                }

            }

            p_dat = p_dat.Distinct().ToArray();

            count = 0;
            for (i = 0; i < m; i++)
            {
                for (j = 0; j < n; j++)
                {
                    if (s_dat[i] == p_dat[j])
                    {
                        count++;
                    }
                }
            }
            Console.WriteLine(count);
            //Console.ReadKey();
        }
    }
}
Re: Почему TLE 8 ? Оптимизировал на сколько мог / Why TLE 8
Posted by Noob 19 Apr 2017 03:46
Потому что два вложенных цикла в конце программы дают n * m операций