4

Common reasons for NO verdict in CP assuming your solution is correct on paper

 2 years ago
source link: http://codeforces.com/blog/entry/104334
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Common reasons for NO verdict in CP assuming your solution is correct on paper

By AmmarDab3an, 17 hours ago,

Since I started competing in competitive programming, I discover more and more ways to get RTE or WA verdicts because of some stupid mistakes I make during the coding phase, I will try to mention some of them here for my future self, and you can also share your experience in the matter.

Initially, I will list them without any specific order, and I may write a proper blog if I find myself with good material, so feel free to comment your thoughts.


- wrong fixed arrays sizes // such as 3*10^5 and 10^6 - #define int int64_t // work smart not hard - #define endl '\n' // one less thing to take care of - 1e9+9 // or any other stupid value - INF vs INFLL // always use INFLL with its value equal to 0x3f3f3f3f3f3f3f3f ("0x" + "3f"*(8)) // this can be used for int32 also - defining void function as a non-void one without returning any thing. // compiler fault and it mostly will works just fine in your machine, not like the judges one. - freopen the wrong file name // sad memories lives here - not printing the size of the answer when the problem asked for it - scanf("%d", (long long)x) - for(int i = 2; i*i <= x; i++) if(!not_prime[i]) // i*i may overflow - while(p%x==0) p/=x; // p may be equal to zero. - n*(n+1)/2 - lcm = x*y/gcd(x, y) // where (x=y=0) - (x-y)%mod // just used good defined adding and multiplying functions - (x+y-1)/y where y < 0 // there is no need to use the trick in negative numbers - x & (1<<p) // use ((x>>p)&1) - for(int i = empty_vec.size()-1; i >= 0; i--) // unsigned integer - for(int i = 0; i < log_n; i++) if(par[u][i] != par[v][i]) // (LCA) // start from the MSB to LSB, not the other way. - for(int i = 0; i < strlen(s); i++) - --upper_bound(vec.begin(), vec.end(), (pair<int, int>) {first, -1}) // use lower_bound({first+1, -1}) or inf instead of -1 - lower_bound(set.begin(), set.end(), element) // you silly - *empty_set.begin(), *--empty_set.end() // you're not trustworthy - x = min(x, map[x]) // map[new element] equal to zero. - multiset.erase(x) - not using size variable in centroid decomposition, hld or small-to-large // very dangerous one - DFSing on other than the 0-th node when filling binary-lifting values (LCA). // par[u][inf]=0 - using a wrongly sorted queue in Dijkstra algo. // multiply by -1 instead of using a greater operator - not re initiating global variables in multi testcases problem. - using memset or fill in a multi test cases problem // be smart and use integer-visited-arrays with visited-id - breaking from the user input loop in a multi test cases problem - segment tree base cases conditions // (r < q_l || q_r < l) // don't trust me with this :) - using 1-indexed bit or sparse table. // never use 1-indexed stuff - [l, r) // who define things this way?? - ~node() // not writing a destruction function for a pointer based segment tree or trie in a multi testcase problem. - new node() // MLE - if(x) where x < 0 - if(x==true && y==true) // put parentheses (acpc kickoff 2020) - if(x&(1<<p)==0 && y==true) // & is evil - b = y&(1<<p); x = child[y][b] // b must be a boolean not 2^p - to_string // write it yourself - std rand function // use mt19937 - const bool debug = true // check any debug-related stuff like watchers - Yes vs YES - alic and bobe - n==1 or even n==0 - use array<> instead of vector<> when size is fixed - return answer // return mem[x] = answer - return x <= y // in user defined compair functions - switching between n and m // 15m of awkwardness in a session // spoj.com/problems/LABYR1

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK