devanshsaxena16's blog

By devanshsaxena16, history, 5 months ago, In English,

So I made submission of problem https://codeforces.com/problemset/problem/154/B having submission 54472940 but giving tle on test case 1 while running efficiently and giving correct answer in codeblocks in my pc. Please help if there is any error in my code.

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 months ago, # |
Rev. 2   Vote: I like it +4 Vote: I do not like it

A little work in the custom test tool reveals that something is wrong with your logic that handles the cases that are preceded with the '-' character. It is possibly an infinite loop or undefined behavior. I am not going to spoil the fun of debugging for you. So I'll leave it to you to find out the root cause from here.

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Just don't create static arrays locally ... create them globally with MAXN size i am refering to

bool vis[n]={false};
ll freq[n+1]={0};
set<ll> br[n+1];

just move them to the global scope and make them like this

bool vis[MAXN]={false};
ll freq[MAXN]={0};
set<ll> br[MAXN];

and get AC :)

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

    Just remember that this is considered a very bad practice anywhere other than competitive programming though.

    • »
      »
      »
      5 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks bro

    • »
      »
      »
      5 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      yes ... but competitive programming need very big arrays which we don't usually use in real life (like 1e6 arrays)

      but if you do care about these habits ... just use STL Vector locally :)

  • »
    »
    5 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I would remember that

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I have submitted Your code ... only with this modification and got AC here is a link : https://codeforces.com/contest/154/submission/54477215