Hi everybody!

Today at 12:00 Moscow Time there will be Codeforces Round #279, dedicated for second division contestants. Round is based on the problems of the Saratov second round of All-Russian School Olympiad in Informatics 2014-2015 that is held at the same time in Saratov.

This round was brought to you by ikar, HolkinPV, IlyaLos, fcspartakm that are all members and ex-members of Saratov SU 2 team.

There will be **6** tasks for **2 hours 30 minutes**. Scoring will be announced just before the round starts.

Round will be rated for second divison participants. First division contestants may participate out of competition.

**UPD:** Scoring: 500-1000-1500-2000-2000-2500.

Good luck!

ranked!?

Don't you like ranked contests? Are you racist?

I actually wanted it to be ranked. Some of them weren't in the recent past .

Oh, I'm sure your wishes will be taken into account.

waiting! waiting!!! good luck to all participants!

wish high rating

When you visit codeforces.com

Can you look the message "connecting to fonts.googleapis.com ..." with 10 sec?

Press X then it will load.

The page become blank after press X.

Try to clear your cookies.

6 problems. Wow!!!!!!!!

10 minuets to start. Why yet not scoring have been published? Waiting for it.

Scoring have been published. Best luck to all participants.

For God's sake, why do you down vote? What's wrong with what he said?

Cause he's spamming?

I don't think that he's spamming.

Delay? Again

yep

When it was moved last time, servers were showing they are busy almost all the time, hopefully today it will be better...

hope that also last time I asked to be unrated because of the same reason but they told me they didn't face any problem during contest :D now it seems that it's not mine only :D

There was a lot of contestants complaining, I didn't understand why it was rated, I left the contest earlier also...

Scoring have been published. Best luck to all participants.

Contest not start

Not again! It's becoming a tradition to delay the contest right before it starts!

This time, I am glad the contest got delayed. Forgot to register earlier.

again more 10 minutes waiting :D nice. P.S. good luck everybody

when will i be candidate master???

same problem here :D

Just when you will have the quality to acquire it. Best luck to you in this round. :D

Almost every contest gets delayed these days! Anyone knows what the problem is?

Because the contestants in codeforces are increasing exponentially.

I wish will be candidate master today)

best of luck to you :)

thx!)

Wish granted ;)

I arrived at home just now from school (it's 12:30 here)

I'm so stressful now... :(

Please pray a good contest for me... :(

lucky man. contest will start with delay.

It delays for 10 minutes! Am I right?

Yes, I hope no more delays!!

hmm, you are right.

Good luck to all!

Good luck guys !

Its good that this contest has 6 problems. Better chance to improve ratings. Wishing high ratings to everyone :)

Really? It depends on number of problems? I don't think so...

Its not always correct, but most of the times it is easier to solve 3 problems out of 6 than solving 3 out of 5. Of course, it includes the fact that you should solve the 3 problems fast.

Is there any way to help Codeforces to strengthen its servers ? I think it worth to pay for having a faster and stronger programming contest platform.

Can you unblock gym?

Hello, why all problem pages are blocked? is this because contest is running?

Does the interface always inform about hacks with delay?

I got a message about my stupid C solution being hacked only after about 20 minutes and hadn't enough time to correct it =(

Why all wrote n^2 to C. I earned 5 hacks because of that. (actually n is the length of string)

All my hacked solutions were exactly the same. My test was s = '9' 10^6 times, a = 9, b = 2

Awesome contest! Thanks for the problems. :)

Omg, after I locked my C I found it will fail with

...I'm so unhappy :-(

BTW: where I can test hacking using generator? Because I wanted to try huge input for heu2013201410's solution in my room — 27...

The answer should be "No"? As your test doesn't differ from

120 12 1

Answer is Yes I think — 123 0

I think it's "NO". Both parts should be positive integers that have no leading zeros.

Both the resulting numbers should be positive integers. So the numbers can not be 123 0.

Thats good message, thanks and now its clear, why my hacking failed. Stil better -100 then -1000...

Actually I think answer should be NO according to 3rd test ?!

Wanted to hack solution C by TL with test.

But this test file has size (1e6 + 5) Bytes! And this is more then 256KB. Why does system not allow to upload big tests???

Lost my hack because of this.

How about generator?

You can create generator — program, that generates the input. I wanted to try it first time today also. Motivation is clear, if everyone uploads 1MB big file it is a lot of network traffic...

A generator is a program which outputs the hack input in the correct format. I don't think that you can test it without a contest. Just write one and check if the generated input is ok.

The two parts must be positive integersis zero considered to be a positive integer ?

No, if 0 would be considered into solution, the problem statement should say "non-negative integers"

I know I just reply to Betlista comment

Div.2 C. Couldn't understand why hack attempts were unsuccessful until realized that me forgot expand generated test changing magnitude(10^) from 1 to

6:( .The problem statement of F today was so bad and unclear that I had to read the statement over and over again and rewrite my code about 4 times from scratch because of not understanding what was actually I needed to do. I had to code this problem mostly on assumption. Glad it was only a div-2 contest. I hope the authors will provide easily understandable statements from next time.

why b=1000000007 is invalid test for hacking of C?

The number is too large, look at constraints. Has to be less than 10^8.

oh :| I think it was 10^18 :|||

Because

b≤ 10^{8}Because b must be in range [1..10^8] It clearly said in problem statement

this code is still wrong, but for this tc, it gives right answer and yet it got WA http://codeforces.com/contest/490/submission/8820977

you have extra 9 at the begin of second number

my bad, thx for your info

New contest new color...

Can anyone tell me why am I getting a wrong answer on pretest 4 ? I'm new here! http://codeforces.com/contest/490/submission/8821196 (Ignore the biginteger part,coding begins at the function compute() ) thanks!

Is it wrong because I messed up the concept of leading zeros / trailing zeros?! wrong condition?

Because there is the answer for string "604": "60 4" where both of numbers are divisible by 6 and 4 respectively

What should be the condition to check if there aren't any leading 0s? Is my implementation wrong?

Why can't I see the wrong test case when submitting problem E in practice?

Edit: It's fixed now

Surprisingly fast system test. I thought problem C can be solved using

O(n^{2}) algorithm. Too bad I didn't check the constraint forn. Anyway, thanks for the contest!I think that codeforces should check the IP when a new user registers because i can bet that there are lots of div1 members who make clone accounts in order to participate in div2 rounds with rating and because of that our chances for a lower rating grow. Or we get a lower improvement than we should. Just my opinion.

Some nations do not have static IP.

I know that it cant be that accurate, but at least.. you block few users. With a bit luck, more users :D

IP based check is bad idea. But I have same feelings... Mbaybe solution could be that when there is no Div 1 competition, they will have same problems in and they can compete in speed typing... Or separate ranking can be created for such contests...

When will ratings be updated ???

Anyone on how to approach Problem C. I thought about writing own function to check if the two numbers formed are divisible by the given number : eg. 64010 64 10 check for each value of i 6|4010, 64|010, 640|10 ... for divisibility Will this approach run in time?

try to check forward and backward (will be almost the same like forward )

Yeah I got it. Have to use exponentiation as well.

Thanks

This is my code..have a look..just used the wrong condition to implement trailing 0s condition. Any feedbacks are welcome. http://codeforces.com/contest/490/submission/8821196

the idea starts from the observation:

lets say you have the number 78541

78541%x = ( (7*10^4)%x + (8*10^3)%x + (5*10^2)%x + (4*10^1)%x + (1*10^0)%x )%x

if you dont get the further idea for the solution i will add the next part :D

thanks... i got the idea. Couldn't expand the number during the contest, but I got the answer now. Thanks.

cool, thanks!

For B I allocated

`int[] map = new int[1000000]`

instead of`int[] map = new int[1000001]`

and I got a WA on Test 55 because of that. Cruel!Do people like downvoting stuff just for fun? This community should be a little more mature.

I got TLE in 'C' with O(n) solution. :/

don't use strlen(s), it has O(n) complexity, where n is length of s.

Wasn't knowing that :(

strlen() has a complexity of O(n), not O(1).

So your overall complexity is O(n^2).

you repeatedly called strlen, which has n complexity;

OK

just use c/c++

It depends, what is the solution, for example this ona — http://codeforces.com/contest/490/submission/8818849 have to end with TLE and problem is not in python...

yes, but almost python's solution is correct!

such as this one: http://codeforces.com/contest/490/submission/8818227

I do not know python well, this:

is list? Try to use array, should be quicker...

How I can solve problem C?

Traverse a string in both directions and keep two arrays

ad,bd.For

ad[i] we traverse the string from the left to the right and find the reminders[1:i]%a. There is a formula for this:ad[i] = (ad[i- 1] * 10 +s[i] - '0')%a.For the

bd[i] we traverse string from the right to the left and find the reminders[i+ 1:n]%b. Also we keep the variablebten_{i}which is equal to 10^{i}%b. So there is a formula forbd:bd[i] = (bd[i+ 1] + (s[i] - '0') *bten_{i})%b.Finally we traverse the arrays

ad,bdand search for such indexi, thatad[i] =bd[i+ 1] = 0.thanks~

Could you explain why these formulas work? Or point to a source where this theorems are explained? Thanks

Rating....so late.

Can someone Please explain the idea behind problem C ? in detail preferably. Thank You. :)

http://codeforces.com/blog/entry/14826#comment-198073

If we divide the sequnence into two parts: 1, 2, ..., i and i + 1, ..., n, then we need to check s(1, i) % a and s(i + 1, n) % b. Since s(1, i) % a = (s(1, i — 1) * 10 + s[i]) % a, s(i, n) % b = (s(i + 1, n) + 10^(n — i) * s[i]) % b, we can compute every s(1, i) and s(i, n) within O(n) time firstly. Now, we can check s(1, i) % a and s(i + 1, n) % b within O(1) time.

I Will explain it using an example:

consider the number 116401024(call it N)

we can split it as

If this number is divisible by a number M then the modulus must be 0(i.e. N%M==0), to check this we can do:

Coming to the actual problem

The possible ways we can split the number into two parts are :

now for each of this splits we want to check if the first part is divisible by "a" and second part is divisible by "b".

Now we can modify the above for loop by storing for each index i, whether the part of the number from 0 to i is divisible by a, like this:

Similarly, we can do for b starting from least significant digit of the number.

and once we have

divisible_by_aanddivisible_by_b, we can easily check if we can divide the number into two parts for each index i by the logic:Thank You :)

Call the large number

`s`

and let`n`

be its length.For every prefix, compute

`x[i] = s[0..i] % a`

. For every suffix, compute`y[i] = s[i..n-1] % b`

. Now scan`s`

from left to right and check if`x[i] == 0 and y[i+1] == 0 and s[i + 1] != '0'`

. If this condition holds, we have an answer.Country wise rankings updated.

Can anyone please tell me, why my solution of C always takes 0 or 15 ms and suddenly on test 36 i got TIME_LIMIT_EXCEEDED? There are no cycles or anything and I'm getting really clueless... http://codeforces.com/contest/490/submission/8823963

There's also the weird thing, that it shows my output (which I think isn't supposed to be there, because I shouldn't have time to it), but there is no Answer...

Don't use ansistring. Try to use array of char instead.

where is the editorial?

Can someone explain to me their approach for problem E? I got it accepted in practice but barely under the time limit so I guess there are faster approaches.

What's wrong with checker of problem D ?

Seems like my solution gave a valid answer, but checker haven't noticed that!

1280 can not be reached

Because you cant get 1280 from 2160

What is the approach for Problem B?

My approach:

If we determine the first two elements, we can determine the rest uniquely. -> Make an array X such that X[A[i]]=B[i] for every i. Then answer[i+2]=X[answer[i]] for any i.

The student ID of the second person is X[0]. The first person in the line has a = 0, b = (second person's ID).

The student ID of the first person is A[i] which does not appear in array B. Let id = the first person's ID. There's no student such that b_i = id, because there's no one in front of him! And conversely, the first person is the only student with such property.

We can uniquely determine the first two persons, which determine the rest uniquely.

The total run time is O(n).

My submission

thanks a lot..

please provide the editorial section ..please ASAP

Can someone please explain their approach for

problem E? I got it accepted in practice but barely under the time limit so I guess there are faster approaches.Just find the smallest feasible number every time. I'm not sure what is the best algorithm to find this, but my solution is: First, compare the length of the string with the one of last string, and there are three cases: 1. s[i].size()<s[i-1].size(): impossible, print "NO" 2. s[i].size()>s[i-1].size(): set all '?' to 0 (If it's the first number, set it to '1') 3. s[i].size()==s[i-1].size(): Find the first digit j where s[i] and s[i-1] is different. There are two cases: 1. j==s[i].size(Can't find) or s[i][j]<s[i-1][j]: Find the rightest '?' before digit j whose corresponding digit 'k' in s[i-1] is not '9'(because no digit is larger than 9). If you can't find it, also print "NO". Otherwise, set the '?' to 'k+1'. Then set all '?' before this digit exactly the same as their corresponding digit in s[i-1], and all '?' after this digit to '0'. 2.s[i][j]>s[i-1][j]: Similar to the case 1, but don't need to do the first step because this digit is already larger.

Thank you very much. It's very similar to my solution but I used a recursive approach and I guess that's what's taking my algorithm longer.

I used binary search to solve E.

Here is my submission.

Could you please explain how you used binary search? I didn't understand very well by reading the code.

When I was trying to hack a solution by the output generator, I got a message "FAIL Line [name=public_key] equals to "#include <b...spond to pattern "[1-9][0-9]{0,999999}" (stdin) [validator val.exe returns exit code 3]".

I didn't understand the meaning of it. Please anyone help me how to hack in problem C if anyone use only 10^5 array where I need 10^6.

Do you guys know when the editorial will be published? I am really interested what is the idea for D and how one can figure it out.

Every time Polycapus eats the chocolate, he set one of the number to 2/3 or 1/2. So what you should consider is, whether these two products is the same after dividing all 2 and 3. If it is, you can set the power of 3 to the same number by performing several 2/3 cuts to the one which has more 3, and then set the power of 2 to the same number by 1/2 cuts.

Thank you very much!

My C problem reached TL on test 42. How to solve this problem correctly?

you are using substr and strlen functions and they both have o(n) so your code complexity have o(n^2) runtime. find a way to get ride of them both.

Use bigmod. I think your solution is N^2

The contest is useless. I don't gain any thing throng the contest. The problems are so silly!!!

throng -> through

btw: you can edit the post...

That's really offensive thing to say. They spent a lot of time to write/test problems and put them together.

Sorry for my rude talk.Forgive me please.

But I do think the problems need to be considered.....

Can you be more specific? Can you describe what was silly for each problem?

Eh.. All the problem just add some details on the common problems. Or just problems for details.

Well, I guess I agree with you....

How to solve B?

Is there any tutorial?

The B has a error in your problem description.To give an example, how do you solve in this data? 4 0 2 1 3 3 5 4 0

It's easy to infer that the correct answer is 1 2 3 4 5.. but many programe are not give me this answer but also accept it! please view.

In your example you have n=4, but 5 different ids in the list. Change n to 5 and add a line with "2 4" — then you will get 1 2 3 4 5.

Must change to 5? Oh.. Maybe i have not read this problem carefully..

Your test is wrong not enough information while n == 4 if n == 4 you test data be like this 4 0 2 1 3 2 4 3 0 if n == 5 4 0 2 1 3 2 4 3 5 4 0 try again

In case anyone is looking for the Editorial as I was, it has been posted here.

Hello, When the next contest will be hold?

could you help me please to figure out why WA on test 20 ? http://ideone.com/0AzRks

After reading the tutorial, I realized how unnecessary this solution by me is: http://codeforces.com/contest/490/submission/8829276