jakeob's blog

By jakeob, 18 months ago, In English

I have just submitted to this problem: Problem D but my O(N*In N*log2(1e9)) solution didn't pass test 6. submission Is it because I am using long longs and thus allocating memory too carelessly, or is it just because I am spamming modulo operations while calculating the solution? Any help will be much appreciated

  • Vote: I like it
  • +6
  • Vote: I do not like it

| Write comment?
»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

32 *16*300000 worst case operations are 153 M , that is very slow try eliminating another lnN from there

»
18 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

This code is very far from a point where optimizing modulo calls or integral types makes any sense. Slapping a GCC optimize ("O3") would give you a lot more gains for free, and then caring for branch prediction and cache locality would be much more important than those micro optimization.

Not that any of these matter here. Codeforces problems are meant to test broad complexity, apparently some problems down the road care about optimal complexity and low enough constants but we are still far from this level and you would looking for ways to improve orders of magnitude not scrap a few cycle.

I didnt bother actually understanding what the code does so i may be wrong but this looks like the culprit : ~~~~~ for(int d=0;d<n;d+=2){ for(int i=0;i+d<je[j].size();i++){ ~~~~~ Isnt that the problem ? je[j].size() seems to be a O(n) so these loops would run Sum(n-2*i) i=0..n/2 that is n^2/2 — 2*(n/2)(n/2+1)/2 which is O(n^2). I see how you'd confuse it with nlog2(n) but you'd need d*=2 for that to be true.