Codeforces and Polygon may be unavailable from December 6, 19:00 (UTC) to December 6, 21:00 (UTC) due to technical maintenance. ×

Hepic_Antony_Skarlatos's blog

By Hepic_Antony_Skarlatos, 10 years ago, In English

I was practising in a problem here in codeforces,and I wanted to train my C# skills a bit. So I wrote an answer about the problem,and when I tested it throwed "time limit exceed". I was curious about a faster way,so I checked 2-3 another sources,and I found a very similar one in C++. So I wrote the same program in C++,and my answer was accepted.

Why happened that?

»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Your submission list shows no attempts in C#.

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    click "show unofficial"

  • »
    »
    10 years ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it

    Your C# code TLs because these operations in .Net have O(len(str)) complexity:

    str1 += "1";
    str2 += "1";
    str1 += (check1[i] ?  "1" : "0");
    str2 += (check2[i] ? "1" : "0");
    

    Read about strings in .Net and about StringBuilder class.

    • »
      »
      »
      10 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Ohh that sounds interesting,but what you would suggest to fix that? You suggest to use that "StringBuilder" ?

      • »
        »
        »
        »
        10 years ago, # ^ |
          Vote: I like it +3 Vote: I do not like it

        Yes, StringBuilder will allow you to use that approach you used with the performance you thought it would have.