coco_elon's blog

By coco_elon, history, 8 years ago, In English

NHAY is a SPOJ question involving pattern search. The Link: http://www.spoj.com/problems/NHAY/

My solution gives me TLE. Here is my code: https://ideone.com/A2N6An What are some optimizations that I can apply on my code?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by coco_elon (previous revision, new revision, compare).

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by coco_elon (previous revision, new revision, compare).

»
8 years ago, # |
  Vote: I like it +11 Vote: I do not like it

Every time you call strlen(), it works for O(len), so your code works for O(n^2).

And please, format your code. It's really hard to read it.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks!

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Doesn't Optimizer change the code to a way you said ? I thought c++ optimizer have such things that can detect unchanged values in loops and doesn't recalculate them every time for conditions.

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by coco_elon (previous revision, new revision, compare).