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

Обсуждение задачи 1102. Странный диалог

(C# )Memory limit exceeded ,WHY?
Послано min_jie 16 мар 2009 07:40
First:

using System;
using System.Text.RegularExpressions;

    class Program
    {
        static void Main(string[] args)
        {
            int lenNum = int.Parse(Console.ReadLine());
            for (int i = 0; i < lenNum; i++)
            {
                if (Regex.IsMatch(Console.ReadLine(), "^(?:one|out(?:put)?|in(?:put)?|puton)+$")) Console.WriteLine("YES");
                else Console.WriteLine("NO");
            }
}}


Second:
using System;
    class Program
    {
        static void Main(string[] args)
        {
            int lenNum = int.Parse(Console.ReadLine());
            for (int i = 0; i < lenNum; i++)
            {
                if (Console.ReadLine().Replace("one","").Replace("puton","").Replace("output","").Replace("input","").Replace("out","").Replace("in","")=="") Console.WriteLine("YES");
                else Console.WriteLine("NO");
            }
}}


THIRD:
using System;
    class Program
    {
        static void Main(string[] args)
        {
            int lenNum = int.Parse(Console.ReadLine());
            for (int i = 0; i < lenNum; i++)
                Console.WriteLine(Judge(Console.ReadLine()));
        }


        static string Judge(string input)
        {
            int pos = 0;
            for (int i = input.Length - 1; i >= 0; i--)
            {
                pos++;
                if (pos == 1||pos==4) continue;
                else if (pos == 2)
                {
                    if (input.Substring(i, pos) == "in") pos = 0;
                    else continue;
                }
                else if (pos == 3)
                {
                    if (input.Substring(i, pos) == "one" || input.Substring(i, pos) == "out") pos = 0;
                    else continue;
                }
                else if (pos == 5)
                {
                    if (input.Substring(i, pos) == "input" || input.Substring(i, pos) == "puton") pos = 0;
                    else continue;
                }
                else
                {
                    if (input.Substring(i, pos) == "output") pos = 0;
                    else return "NO";
                }
            }
            if (pos==0) return "YES";
            else return "NO";
        }
    }

All of above fail, because of "Memory limit exceeded".



Edited by author 16.03.2009 07:55
Re: (C# )Memory limit exceeded ,WHY?
Послано JAVATAR 14 июл 2012 02:23
The first input size is greater than 16 mb.
Re: (C# )Memory limit exceeded ,WHY?
Послано JAVATAR 14 июл 2012 02:54
use bytes instead of chars and strings
Re: (C# )Memory limit exceeded ,WHY?
Послано Vladimir Yakovlev (USU) 19 июл 2012 23:19
You got ML in the reading:
Console.ReadLine()
This line may use up to 20 MB of memory (strings are stored in Unicode).

There is a solution with O(1) memory. Try to find it.