Блог пользователя rng_58

Автор rng_58, 11 лет назад, По-английски

Div2 A Colorful Stones (Simplified Edition) (Author: rng_58)

In this problem you just need to implement what is written in the statement. Make a variable that holds the position of Liss, and simulate the instructions one by one.

Div2 B Roadside Trees (Simplified Edition) (Author: snuke)

The optimal path of Liss is as follows: First she starts from the root of tree 1. Walk up the tree to the top and eat a nut. Walk down to the height min(h1, h2). Jump to the tree 2. Walk up the tree to the top and eat a nut. Walk down to the height min(h2, h3), ... and so on.

Div1 A / Div2 C Escape from Stones (Author: DEGwer)

In this problem, there are many simple algorithms which works in O(n). One of them (which I intended) is following:

You should prepare 2 vectors. If s[i] = 'l', you should push i to the first vector, and if s[i] = 'r', you should push i to the second vector. Finally, you should print the integers in the second vector by default order, after that, you should print the integers in the first vector in the reverse order.

This algorithm works because if Liss divides an interval into two intervals A and B and she enters A, she will never enter B.

Div1 B / Div2 D Good Sequences (Author: DEGwer)

The main idea is DP. Let's define dp[x] as the maximal value of the length of the good sequence whose last element is x, and define d[i] as the (maximal value of dp[x] where x is divisible by i).

You should calculate dp[x] in the increasing order of x. The value of dp[x] is (maximal value of d[i] where i is a divisor of x) + 1. After you calculate dp[x], for each divisor i of x, you should update d[i] too.

This algorithm works in O(nlogn) because the sum of the number of the divisor from 1 to n is O(nlogn).

Note that there is a corner case. When the set is {1}, you should output 1.

Div1 C / Div2 E Choosing Balls (Author: hogloid)

There are many O(Q * N * logN) solutions using segment trees or other data structures, but probably they will get time limit exceeded.

We can solve each query independently. First, let's consider the following DP algorithm.

dp[c] := the maximal value of a sequence whose last ball's color is c

For each ball i, we want to update the array. Let the i-th ball's color be col[i], the i-th ball's value be val[i], and the maximal value of dp array other than dp[col[i]] be otherMAX. We can update the value of dp[col[i]] to dp[col[i]] + val[i] × a or otherMAX + val[i] × b. Here, we only need to know dp[col[i]] and otherMAX. If we remember the biggest two values of dp array in that time and their indexes in the array, otherMAX can be calculated using the biggest two values, which always include maximal values of dp array other than any particular color.

Since the values of dp array don't decrease, we can update the biggest two values in O(1). Finally, the answer for the query is the maximal value of dp array.

The complexity of the described algorithm is O(QN).

Div1 D Colorful Stones (Author: rng_58)

First, let's consider a simpler version of the problem: You are given a start state and a goal state. Check whether the goal state is reachable from the start state.

Define A, B, C, and D as in the picture below, and let I be the string of your instructions. A and B are substrings of s, and C and D are substrings of t.

It is possible to reach the goal state from the start state if there exists an instruction I such that:

  • 1 A is a subsequence of I.
  • 2 B is not a subsequence of I.
  • 3 C is a subsequence of I.
  • 4 D is not a subsequence of I.

So we want to check if such string I exists. (string s1 is called a subsequence of s2 if it is possible to get s2 by removing some characters of s1)

There are some obvious "NO" cases. When D is a subsequence of A, it is impossible to satisfy both conditions 1 and 4. Similarly, B must not be a subsequence of C. Are these sufficient conditions? Let's try to prove this hypothesis.

To simplify the description we will introduce some new variables. Let A', B', C', and D' be strings that can be obtained by removing the first characters of A, B, C, and D. Let c1 and c2 be the first characters of A and C.

Suppose that currently the conditions are satisfied (i.e. D is not a subsequence of A and B is not a subsequence of C).

  • If c1 = c2, you should perform the instruction c1 = c2. The new quatruplet will be (A', B', C', D') and this also satisies the conditions.
  • If c1 ≠ c2 and B' is not a subsequnce of C, you should perform the instruction c1. The new quatruplet will be (A', B', C, D) and this also satisies the conditions.
  • If c1 ≠ c2 and D' is not a subsequnce of A, you should perform the instruction c2. The new quatruplet will be (A, B, C', D') and this also satisies the conditions.

What happens if all of the above three conditions don't hold? In this case A and C have the same length and A = c1c2c1c2..., B = c2c1c2c1. In particular the last two characters of A and B are swapped: there are different characters x and y and A = ...xy, B = ...yx. Now you found a new necessary condition! Generally, if A and B are of the form A = ...xy and B = ...yx, the goal state is unreachable. If the last instruction is x, Vasya must be in the goal before the last instruction, but then Vasya will go further after the last instruction. If the last instruction is y, we will also get a contradiction.

Finally we have a solution. The goal state is reachable from the start state if and only if D is not a subsequence of A, B is not a subsequnce of C, and A and C are not of the form A = ...xy, C = ...yx. The remaining part is relatively easy, so I'll leave it as an exercise for readers.

Div1 E Roadside Trees (Author: snuke)

For this problem there are slides: Please check here.

UPD: Thank you for pointing out mistakes. They are fixed.

Полный текст и комментарии »

Разбор задач Codeforces Round 162 (Div. 2)
Разбор задач Codeforces Round 162 (Div. 1)
  • Проголосовать: нравится
  • +54
  • Проголосовать: не нравится

Автор rng_58, 11 лет назад, перевод, По-русски

Привет!

Я белочка Лисска. Я буду главным действующим героем сегодняшнего соревнования. Авторами соревнования являются snuke, hogloid, DEGwer, и rng_58. Я хочу поблагодарить Gerald за помощь в подготовке соревнования, Delinur за перевод условий, и MikeMirzayanov за платформу Codeforces. Распределение баллов по задачам будет стандартным: 500-1000-1500-2000-2500, в обоих дивизионах.

Я столкнусь с множеством трудностей, связанных с камнями, орешками и последовательностями... Пожалуйста, помогите мне!

Так как 19:30 MSK очень позднее время для нас (речь идет о времени в Японии), раунд будет перенесен на 17:00 MSK. Вы можете посмотреть время начала соревнования для Вашего часового пояса на timeanddate.com: http://timeanddate.com/worldclock/fixedtime.html?iso=20130120T22&p1=248&ah=2

UPD: Опубликованы все другие детали соревнования.

Это перевод оригинального поста автора с английского языка. Комментарии на английском приветствуются.

Top 5 участников в div1:

В div2:

Поздравляю!

Также наши поздравления участникам al13n и Komaki, которые решили задачу E в первом дивизионе.

Авторы задач:

Разбор будет опубликован завтра (возможно, частично сегодня).

Полный текст и комментарии »

  • Проголосовать: нравится
  • +446
  • Проголосовать: не нравится

Автор rng_58, 11 лет назад, По-английски

My solution depends on the following hypothesis. Can anyone prove this?

Sorry, the image doesn't work for some reason. \sum_{i=1}^{a} \sum_{j=1}^{b} \sum_{k=1}^{c} d(ijk) = \sum_{gcd(i,j)=gcd(j,k)=gcd(k,i)=1} [\frac{a}{i}][\frac{b}{j}][\frac{c}{k}] Now it works.

Sorry, please type "http://rng.gozaru.jp/cf.png" directly to the address bar.

Finally proved: "http://rng.gozaru.jp/b.pdf"

Полный текст и комментарии »

  • Проголосовать: нравится
  • +91
  • Проголосовать: не нравится

Автор rng_58, 12 лет назад, По-английски

Today I participated in Facebook Hacker Cup Round 3. 100 people participated and top 25 will advance to the onsite round in California.


The contest has started. I glanced at titles of problems and samples, and decided to solve "Divisor Function Optimization" first. It was a number theory problem, so I was confident that I can solve this problem. However, after thinking for a while, I noticed that I need to calculate all primes <= 2^250000! (of course, it turned out to be wrong later.) It seemed to be impossible, so I read the other two problems.

"Trapezoids". My first implession was (I don't know whether it's correct or not): convert trapezoids to rectangles in 2D plane and do some sweep line algorithm. It looked hard to implement, so I decided to skip it.

"Unfriending". Try all local-maximal subsequences that can be removed? It's quite easy! I implemented and debugged... oh, I didn't read the problem correctly!

Meanwhile a few people solved "Trapezoids", but let's return to "Divisor Function Optimization". I missed one condition! b/a <= 25! Then it's quite easy, just solve for each prime independently and calculate the product. (there's some more details, e.g. precalculating product of primes, but I'll omit details here.)

I implemented, debugged, and passed all examples. I tested maximal case (actually it wasn't): (a = 250000, b = 10000) * 100000 times. It worked in 13s, which means 260s for 20 max data, so I decided to submit.

I downloaded the input file carefully, saved it on my computer, and executed my program: "./a < divisor_function_optimization.txt | tee divisor.out" But my program worked very slowly.

30 seconds left...

Case #19: 49898798639490 49944512088364...

Looks very dangerous.

Finally 8 seconds before the deadline,

Case #20: 49843150065040 49981240725189

I clicked "submit" button very quickly.

Then my sad story comes. I saved output file in D:/facebook folder, but the browser shows different folder! I don't have time to find D:/facebook!

...I got upset and immediately went to bed.


Two lessons:

1) When time limit is tight, use computer as quickly as possible.

2) Check current folder of the browser before the program terminates!

Полный текст и комментарии »

  • Проголосовать: нравится
  • +198
  • Проголосовать: не нравится

Автор rng_58, 14 лет назад, По-русски

I started to learn Russian recently. I'll write blog in Russian here to improve my Russian skills. Today I introduce myself.

Я узнаю русский. Я рнg_58.
Я японеца. Я учущийсю.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

Автор rng_58, 14 лет назад, По-английски
  • Проголосовать: нравится
  • -6
  • Проголосовать: не нравится