I have started learning JAVA recently. I wrote a code for this problem.

Reference to my code is here.

I can't find out why it is giving me TLE. Can someone help out?

**UPD** : I found the problem. I needed to keep `1 << 20`

in parenthesis.

# | User | Rating |
---|---|---|

1 | tourist | 3947 |

2 | ecnerwala | 3654 |

3 | jiangly | 3627 |

4 | jqdai0815 | 3620 |

5 | orzdevinwang | 3612 |

6 | Benq | 3586 |

7 | Radewoosh | 3582 |

8 | Geothermal | 3569 |

8 | cnnfls_csy | 3569 |

10 | ksun48 | 3474 |

# | User | Contrib. |
---|---|---|

1 | awoo | 163 |

2 | maomao90 | 160 |

3 | adamant | 156 |

4 | atcoder_official | 155 |

5 | maroonrk | 152 |

6 | -is-this-fft- | 148 |

6 | SecondThread | 148 |

8 | Petr | 147 |

9 | cry | 145 |

9 | nor | 145 |

I have started learning JAVA recently. I wrote a code for this problem.

Reference to my code is here.

I can't find out why it is giving me TLE. Can someone help out?

**UPD** : I found the problem. I needed to keep `1 << 20`

in parenthesis.

I have seen these lines in codes of various people. People use it for debugging. Can someone please explain how it works?

```
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
```

How to solve this problem using matrix exponentiation. The recurrence relation is :

*f*(*n*, *k*, 0) = 2 * *f*(*n* - 1, *k*, 1) + *f*(*n* - 1, *k*, 0)

*f*(*n*, *k*, 1) = *f*(*n* - 1, *k*, 1) + *f*(*n* - 1, *k*, 0)

1 < *n* < 1*e*9

1 < *k* < 1*e*3

I implemented a code for Problem 55 of Project Euler. It is giving me an incorrect answer. This my code.

Can anyone help me, to find the bug?

**THOSE WHO DID NOT SOLVE IT, PLEASE DO NOT OPEN THE CODE. IT WILL BE A SPOILER.**

If I want to implement trie using two dimensional array, how should I decide the size of array.

I have implemented 903D using Mergesort Tree and maintaining a prefix sum vector for every vector of merge sort tree.

For every a[i], I am calculating the sum of all a[j], where a[j] > a[i]+1 or a[j] < a[i]-1, j < i. Using this sum I am subtracting this sum from answer and adding a[i], same number of times.

My submission. This error is because of integer overflow, but when I change all integers to long long. It gives me wrong answer.

Any help would be appreciated. :)

I think some will agree with my opinions and some might feel it is not necessary in Competitive Programming. But, I feel that programming is not just about writing a correct a code that solves the purpose, but also how the code looks.

Everyone have their own style of writing codes. One of the persons whom I admire the most is rajat1603(Rajat De). Rajat's codes are very well formatted and obviously they are correct. I think the people who are learning from reading other's code get benefited from these beautiful codes a lot. I personally feel very happy after seeing Rajat's code. There are also various other coders who code beautifully like our legendary champion tourist(Gennady Korotkevich).

I just want to advice everyone to write your codes like its your personal signature, follow your own style and maintain a symmetry. Try it, feels good. I am not a very good problem solver neither a good blogger. I just love beautiful codes.

Please give suggestions, how this can be encouraged.

- Extra points can be awarded if possible during contests.
- A new rating like contribution and contests rating for code beauty.

I have seen two implentation of DFS that people generally use.

```
bool visit[N];
int par[N];
vector<int> g[N];
void dfs1(int v)
{
visit[v] = true;
for(auto child : g[v])
{
if(!visit[child])
dfs1(child);
}
}
void dfs2(int v, int p)
{
par[v] = p;
for(auto child : g[v])
{
if(child == par[v])
continue;
dfs(child,v);
}
}
```

What is the difference between these two implementations? Is the second implementation only used when we need parent or some other cases also. I always maintain visit array, but some people don't does it affect. I think it should cause infinite recursion but it doesn't.

Can someone please explain it in details.

Can this problem problem be solved using segment tree. If yes can anyone can tell how to build Seg tree.

During combining two segments how do i check for mid and (mid+1)th element in merged segement.

Some people have done k=k%1024, I don't understand why? Can someone tell me.

Problem link here.

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Aug/07/2024 03:34:34 (g1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|