DryukAlex's blog

By DryukAlex, 13 years ago, In Russian

Twice I got TL with time 0.031 and 0.015 respectively. Who knows what does it mean?;)

http://acm-judge.usu.ru/status.aspx?space=1&num=1804&author=89474

  • Vote: I like it
  • +11
  • Vote: I do not like it

13 years ago, # |
  Vote: I like it 0 Vote: I do not like it
Code was the same all three times?
13 years ago, # |
  Vote: I like it +1 Vote: I do not like it
Most likely it is "idleness limit exceeded"
maybe you waste memory and program do nothing
  • 13 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    Interesting. Couldn't you give me this test - I'd like to check it in my computer.
  • 13 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    The only thing that differs in TL and AC solutions is that in TL one I use an array of strings and read some of the elements for this array more than once. For example,
    ...
    string mas[5];
    void main
    {
    ...
    cin>>mas[0];
    ...
    cin>>mas[0];
    ...
    }

    Could it cause any problems?
13 years ago, # |
  Vote: I like it +1 Vote: I do not like it
In your TL solutions sometimes you write to the memory out of arrays, so behavior of the program becomes unpredictable. For example, on g++ it just crashes. On timus it works for few seconds before getting TL, so it really seems to be idleness limit exceeded. Just check your indices in code carefully or test on any reasonable large input and you will find your error. 
  • 13 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    >>Just check your indices in code carefully or test on any reasonable large input and you will find your error.
    and you can write this in top of your code:

    #define _GLIBCXX_DEBUG

    when you wrote this code, your programm returns RE when you using indices, which are out of range

    • 13 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      #define _GLIBCXX_DEBUG
      #include <cstdio>
      int main()
      {
      int ar[5]; int sum = 0;
      for(int i = -2; i <= 6; i++)
      {
      ar[i] = i;
      sum += ar[i];
      }
      printf("%d\n", sum);
      return 0;
      }

      It works without any errors on my g++ 4.4.5.
      The only reliable way to have runtime indices check I know is using std::vector and .at(). But it is a bit slower.
      • 13 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it
        Sorry, but how can I write to the memory out of array when I have the array of 5 elements and I call only the elements from 0 to 4?..
        The part of my code which causes problems is as follows:

        string mas[5];
        ...
        int main()
        int t;
        {
        cin>>t;
        for (int i=0;i<t;i++)
        {
        int a,b;
        bool f;
        for (int j=0;j<3;j++)
        cin>>mas[i];
        cin>>mas[3];
        if (mas[3]=="home") f=true;
        else f=false;
        cin>>mas[3]>>mas[4];
        cin>>a;
        for (int j=0;j<3;j++)
        cin>>mas[i];
        cin>>b;
        cin>>mas[0];
                        ...
        }
        return 0;
        }
        • 13 years ago, # ^ |
            Vote: I like it +3 Vote: I do not like it

          As I have already told - check indices carefully.

          for (int j=0;j<3;j++) cin>>mas[i];

          And i may be larger than 4.