← Back to topics
Topic

Insane TimeLimits

t
thocevar
I've come across quite a few problems here on z-training, where the major factor was how you read input data. On some tasks I could only get accepted with Pascal and not with C. I don't see the point in so tight limits and it can be pretty frustrating.

One example is task z-blocks from recent Z-Teams #1 competition. Most straight-forward solution passed in C but not in Pascal. I guess we got luckier with compiler optimizations.

But there's an even worse trick, my favourite is z-ram from ZCM #4. Here's a story how I passed. I took a wild guess that number of selected rows will always be smaller than number of selected columns. Don't ask how this managed to pass without WA. Anyway, afterwards I've borrowed code from someone else with rather fast submission and started modifying it back to my original code.
Here are three snippets(same thing, with small changes) of table allocations from my code:

int bits[1<<20];
int rs[21];

char bits[1<<20];
char rs[21];

char rs[21];
char bits[1<<20];

First option doesn't pass, neither does the second one. However, third one turns out to be 3 times faster!

I'm sure everyone would appreciate it, if there was a bit more room for solutions which are not so perfectly tailored for compiler's optimizations.