Hello!

I'm, Valeriy Samojlov, graduating student of SPbSU, present you codeforces beta round 79. Today you will meet with boy Gerald and will help him to solve some living problems.

Today we have usually cost of problems in both divisions: 500 - 1000 - 1500 - 2000 - 2500.

It my first codeforces round, I hope, problems will be interesting.

I want to thank Artem Rakhov (RAD) for big help with preparation of problems, Makar Krasnoperov (Connector) for some useful remarks and Maria Belova for translation.

Good luck for participants of both dovisions!

Contest is over! Congratulation to winners!

__Division 1:__

1. RAVEman

2. ilyakor

3. ACRush

__Division 2:__

1. SuperLight

2. xiaowuc1

Editoral a appeared.

Nice contest. :)

What is the complexity of the intended solution for problem D div 2? O(m) ? O(m*log(m))?

I tried to implement a O(m) algorithm, but maybe there is a simpler one in O(m*log(m))?

Any help appreciated!

The main idea is:

If not, it's really weird. A lot of AC solution have complexity O(m log(m))...

Besides, I'm not a big fan of Java, but if it passes arrays around by copy, that's a huge overhead that you are not using class variables for the arrays...

Regarding java, I don't think it passes a new copy of the array. for objects more than the primitive data types, it passes the object as a pointer to the same memory location.

Call num[t] = number of ways from the position t (a bus stop or the value 0).

num[max_t] = 1 and the result to return is num[0].

the update rule at time t is:

num[t] = c*num[next_t]

where t is a bus final stop, and next_t is the next position where a bus stops.

and c is either r or r+1

with r = number of buses that start before or at t, and stop at exactly next_t.

c = r+1 if there is a bus that starts before or at t, and stops strictly after next_t,

c = r otherwise.

I see how to get the value r in O(log m),

but to determine efficiently whether c should be r or r+1, I'm at a loss.

Anyone knows? Or is there a simpler way to look at it?

Thanks for your help.

num[t]as the number of ways to reach the end from positiont(and then solving back to front), definenum[t]as the number of ways to reachtfrom the start.With that definition,

num[0] = 1, obviously, and to computenum[t]for increasing values oft, we can do:for each bus starting at

sand endingt:for

s <= i < t:add

num[i]tonum[t]Of course, we must first compress the coordinates into a range O(M) so our

numarray is small enough. Additionally, to avoid anO(M)inner loop, we can keep track of the accumulated sum ofnum[0..i]; with that, we can compute sums ofnum[i..j]efficiently too.If you can read C++, my commented solution shows the details.

By the way: don't feel too bad about not being able to solve this one. I thought it was a pretty hard problem, despite its point value. I'm rated red here, but I could not figure this out to save my life during the contest!

It's tricky to adapt the outer loop to include the computation of num[0..i] from num[0..i-1] in O(1).

This is convenient, because we can just try the four possible rotations of A and subtract them from B. Then the question becomes if we can express the resulting vector with integer coordinates in an orthogonal system with C and its rotation as axes.

So after we compute

D = (B - rotfor^{i}(A))i={0,1,2,3}we want to check if there are integersxandysuch thatx*C + y*rot(C)=D. SinceCandrot(C)are orthogonal, we can decomposeDinto independent components using scalar projection, and from there we can compute the value ofx(or, in this case, just check if its integral). For example,xis integral iffC·D = 0 mod |C|, where · is the dot product.^{2}A different approach for the last part is to write the equation

x*C + y*rot(C)=Das a system of linear equations (C,rot(C)andDare all known) and solve that using Gauss-Jordan elimination. This is a bit more work if you don't have code prepared for this, but requires less thinking if you do.it should be %I64d instead in this contest ?

Both POSIX and ANSI C allow

llas a size prefix, but Microsoft doesn't implement either standard.If GCC on Windows calls the printf() implementation in Microsoft's C library, then it probably behaves incorrectly too. The fact that it works on Linux is not thanks to GCC, but thanks to the GNU C library.

when you needthem it is specified on the statement.I think so. Let me check again.

Yes, I'm 100% sure. Why do you ask?

A little bit more seriously (sorry): My intention was to protect the poor twits who first click without understanding the text, and then think and use Google Tranlate.

I wish we were able to flag posts as spam, in addition to negative votes. Where is the right place to request the feature? :)

I don't think there are much people on this site that click on every link they see without understanding it.