When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

devanshsaxena16's blog

By devanshsaxena16, history, 5 years 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.

| Write comment?
»
5 years 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 years 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 :)