错误-NZEC-C#-HackerEarth

时间:2018-07-08 12:10:52

标签: c# runtime-error

我有一个代码可以在我的PC上以及HackerEarth提供的控制台中正常工作(带有自定义输入),但是在Hacker Earth上提交该代码时,它在53个示例中的2个测试用例中返回了NZEC运行时错误。  This is the problem description
这是我的解决方案:

fn_GetColumns(1)

我认为问题在于为词典分配了过多的内存。 这些是我遇到运行时错误的2个测试用例:

SELECT * FROM Names

这个测试用例很小,但是它也返回错误。

using System;
using System.Collections.Generic;

class Test
{
    static int xx1=-1, yy1=-1, xx2=-1, yy2=-1,dyy=-1;

    static  void store(int x1,int x2,int y1,int y2,int dy)
    {
        dyy = dy;
        xx1 = x1;
        xx2 = x2;
        yy1 = y1;
        yy2 = y2;
    }

    public static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());

        var a = new Dictionary<int, SortedSet<int>>();

        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Trim().Split(' ');
            var x = int.Parse(s[0]);
            var y = int.Parse(s[1]);
            if (a.ContainsKey(x))
            {
                a[x].Add(y);

            }
            else
            {
                var set = new SortedSet<int>();
                set.Add(y);
                a.Add(x,set);
            }
        }

            foreach(KeyValuePair<int, SortedSet<int>> entry in a)
            {
                var set = entry.Value;
                foreach (int j in set)
                {
                    foreach (int k in set)
                    {
                        if (k > j)
                        {
                            int y1 = j,x1=entry.Key,y2=k;
                            int dy = y2 - y1;
                            int x2 = x1 + dy;

                            if(a.ContainsKey(x2) && a[x2].Contains(y1) && a[x2].Contains(y2))
                            {
                                if (dy > dyy)
                                {
                                    store(x1,x2,y1,y2,dy);
                                }
                                else if (dy == dyy)
                                {
                                    if (y1 < yy1)
                                    {
                                        store(x1,x2,y1,y2,dy);
                                    }
                                    else if(y1 == yy1)
                                    {
                                        if (x1 < xx1)
                                        {
                                            store(x1,x2,y1,y2,dy);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

        if (xx1 == -1) Console.WriteLine(-1);
            else Console.WriteLine(xx1+ " "+yy1);

    }
}

0 个答案:

没有答案
相关问题