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 1209. 1, 10, 100, 1000...

Test #3 -Time limit exceeded (C#)
Posted by Arantir 28 Nov 2011 03:06
Why it is so slowly??? I use standard formula with "sqrt(8*N-7)".

            int L = int.Parse(Console.ReadLine());
            string answer = "";
            for (int i = 0; i < L; i++)
            {
                if (Math.Sqrt(8 * long.Parse(Console.ReadLine()) - 7) % 1 == 0) answer += "1 ";
                else answer += "0 ";
            }
            Console.Write(answer);

I can't imagine shortest solution... What's the matter?
Many people has used C# successful in problem 1209.

Edited by author 28.11.2011 03:09
Re: Test #3 -Time limit exceeded (C#)
Posted by Reza 23 Dec 2011 17:37
I don't know c# but I think it's correct.


why you don't use c++?
Re: Test #3 -Time limit exceeded (C#)
Posted by PlayLinsor 14 Aug 2013 15:52
Arantir wrote 28 November 2011 03:06
Why it is so slowly??? I use standard formula with "sqrt(8*N-7)".

            int L = int.Parse(Console.ReadLine());
            string answer = "";
            for (int i = 0; i < L; i++)
            {
                if (Math.Sqrt(8 * long.Parse(Console.ReadLine()) - 7) % 1 == 0) answer += "1 ";
                else answer += "0 ";
            }
            Console.Write(answer);

I can't imagine shortest solution... What's the matter?
Many people has used C# successful in problem 1209.

Edited by author 28.11.2011 03:09
Compare with this code
static void Main(string[] args)
        {
            int len = int.Parse(Console.ReadLine());
            int[] mas = new int[len];
            int max = 0;
            for (int f = 0; f < len; f++)
            {
                mas[f] = int.Parse(Console.ReadLine());
                if (mas[f] > max) max = mas[f];
            }

            foreach (long i in mas)
            {
                double ig = (Math.Sqrt(8*i-7))%1;
                if (ig == 0) Console.Write("1 ");
                else Console.Write("0 ");
            }


        }