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 | 3985 |
2 | jiangly | 3741 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3489 |
7 | Radewoosh | 3483 |
8 | Kevin114514 | 3442 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
2 | atcoder_official | 162 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | nor | 150 |
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 < 1e9
1 < k < 1e3
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.
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.
Hello to Codeforces community. This not like I want to share some of my knowledge. Its just a request for some experienced coders to give some information regarding their journey on codeforces. Beginning from their coding life as a low level coder to becoming red or orange coders. It will give a lot of inspirition to inexperienced coders like us. I would be delighted and thankful to them who would share their experiences.
Name |
---|