ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1119. Метро

Please give me test case 10. My program passes all the tests I found here.
Послано Alex 14 мар 2017 12:32
What do i wrong?

using System;
    using System.Collections.Generic;

    public class Program
    {
        /// <summary>
        /// The main.
        /// </summary>
        public static void Main()
        {
            var sizeStr = Console.ReadLine().Split(' ');

            var size = new KeyValuePair<int, int>(int.Parse(sizeStr[0]), int.Parse(sizeStr[1]));

            int k = int.Parse(Console.ReadLine());
            var coordDiag = new List<KeyValuePair<int, int>>(k);
            for (int i = 0; i < k; i++)
            {
                string[] coordDiagForOne = Console.ReadLine().Split(' ');
                coordDiag.Add(new KeyValuePair<int, int>(int.Parse(coordDiagForOne[0]), int.Parse(coordDiagForOne[1])));
            }

            int x = 1;
            int y = 1;
            var diagLength = Math.Sqrt(20000);
            double result = 0;

            while (true)
            {
                if (k == 0)
                {
                    Console.WriteLine((size.Value + size.Key) * 100);
                    break;
                }

                if (k == 1)
                {
                    Console.WriteLine(Math.Round((size.Value + size.Key - 2) * 100 + diagLength));
                    break;
                }

                if (coordDiag.Exists(_ => _.Key == x && _.Value == y))
                {
                    result += diagLength;
                    x += 1;
                    y += 1;
                }
                else
                {
                    if (coordDiag.Exists(_ => (_.Key == x && _.Value >= y) || (_.Key >= x && _.Value == y)))
                    {
                        int counterForX = 10000000;
                        int counterForY = 10000000;

                        for (int i = 0; i < coordDiag.Count; i++)
                        {
                            if ((coordDiag[i].Key == x && coordDiag[i].Value >= y) || (coordDiag[i].Key >= x && coordDiag[i].Value == y))
                            {
                                int stepX = coordDiag[i].Key - x;
                                int stepY = coordDiag[i].Value - y;

                                if ((stepY < stepX && stepY > 0) || stepX <= 0)
                                {
                                    if (counterForY > stepY)
                                    {
                                        counterForY = stepY;
                                    }
                                }
                                else if (stepX > 0)
                                {
                                    if (counterForX > stepX)
                                    {
                                        counterForX = stepX;
                                    }
                                }
                            }
                        }

                        if (counterForY < counterForX)
                        {
                            if (!coordDiag.Exists(_ => _.Key >= x + 1 && _.Value >= y + counterForY + 1)
                                && coordDiag.Exists(_ => _.Key >= x + counterForX + 1 && _.Value >= y + 1))
                            {
                                x += 1;
                                result += 100;
                            }
                            else
                            {
                                y += 1;
                                result += 100;
                            }
                        }
                        else
                        {
                            if (!coordDiag.Exists(_ => _.Key >= x + counterForX + 1 && _.Value >= y + 1)
                                && coordDiag.Exists(_ => _.Key >= x + 1 && _.Value >= y + counterForY + 1))
                            {
                                y += 1;
                                result += 100;
                            }
                            else
                            {
                                x += 1;
                                result += 100;
                            }
                        }
                    }
                    else if (x<size.Key+1 && y < size.Value+1)
                    {
                        result += 200;
                        x += 1;
                        y += 1;
                    }
                    else if(x == size.Key + 1 && y < size.Value + 1)
                    {
                        result += 100;
                        y += 1;
                    }
                    else if(x < size.Key + 1 && y == size.Value + 1)
                    {
                        result += 100;
                        x += 1;
                    }
                }

                if (x - 1 == size.Key && y - 1 == size.Value)
                {
                    Console.WriteLine(Math.Round(result));
                    break;
                }
            }
        }
    }