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

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

The USACO 2015 February contest is available from February 20 through February 23. The contest is 4 hours in length, and can be taken any time during the larger contest window. More info: http://usaco.org/

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

»
9 лет назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

what does it mean "File name may only have alphanumeric characters, underscores (_) and periods (.)"? It is the first time I use C++ in an USACO contest?

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Those rules are describing the source file that you submit. In particular you can name your solution things like "my solution.cpp", "naïve.cpp", "n^2.cpp".

»
9 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

4 hours left! Hurry up if you haven't participated yet.

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Расскажите, как решать 1 задачу (серебро) на 100. Спасибо. Неплохо бы услышать идеи решения 3 задачи о XOR.

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    В первой задаче зашли хэши. Добавляем буквы в ответ по одной, считаем хэши префиксов. Если длина ответа больше, чем длина вырезаемой строки, то хэшами проверяем совпадение. Чтобы не делать операции удаления из строки-ответа, я записывал ответ в массив char'ов и при удалении строки передвигал указатель на текущий символ назад.

    В третьей задаче можно заметить, что при соединении игравших друг с другом команд получится дерево. Нам нужно найти остовное дерево максимального веса, для чего достаточно модифицировать сортировку в алгоритме Крускалла.

    • »
      »
      »
      9 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      А есть ли решение без хэшей?

      • »
        »
        »
        »
        9 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Видимо, можно еще строить префикс-функцию для строки T + '#' + ans. В остальном решение будет аналогично.

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    А 1 в серебре, такая же как и в бронзе (есть текст и строка, надо удалять вхождения строки в текст, учитывая появление новых вхождений и |s|<=10^6 |t|<=100)?

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Is the contest finally over?

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I wish they'd return the old system with testing only after the contest, it was like the only competition besides COCI held this way(does COCI use this system now btw?), but COCIs aren't virtual and they often have ridiculous time limits for Java.

If they could also show your results right after your 4 hours(not 2 days after everyone finished), that'd be just perfect!

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится +48 Проголосовать: не нравится

    Well, I believe USACO's main goal is selection and training for IOI and IOI has full feedback, so their decision was quite logical.

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Anything regarding results ? It's been 4 hours since the contest finished, but no news of results on the website...

They said the results would be out shortly after contest.

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone give me some hints on the second and third problem (Gold division, "censor" and "fencing") ?

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    For the second one you need an algorithm for multiple pattern matching (I used Aho Corasick)

    • »
      »
      »
      9 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      I haven't known that algorithm. If that is the official solution, I had no chance in this contest.

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    For censor, you can precompute the hashes for each substring of the N censored words. Then when doing the deletion, you can maintain pointers so that you can recompute hashes. I didn't do this during the contest, I did a KMP which received 12/15

  • »
    »
    9 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +10 Проголосовать: не нравится

    Third problem can be solved using sqrt decomposition:

    1) we should group all requests to about sqrt(n) groups,

    2) before processing each group we should build convex hull with O(n) time (all points we can sort before processing requests),

    3) before processing each group we should sort all lines by angle and process them with convex hull with pointers,

    4) and finally for each line we should process new points from block of requests.

    So solution has O(n sqrt(n) + n log(n)) complexity.

»
9 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Hey! Can anybody explain the solutions for Silver 1 and 3 or give me some hints, please? For the first one I'm using hash to find a match and then I am deleting it in O(N). I thought about speeding the deleting operation up with segment tree but there was no time for implementing it. I've got 11/15 in total. After the contest a friend of mine told me that the idea with segment tree didn't help him. For the third problem I just use the brute-force solution. I tried to simulate the process 10000 times, every time taking two random teams but this received only 1/10(as the brute-force solution).

Update: Problem 1, Problem 3.

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

    Link to problem(s)?

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится +4 Проголосовать: не нравится

    For problem 3, consider the complete graph where the nodes are the teams and the edges are the potential scores if they play a game. Our result must be a subset of the edges of this graph. Notice that because after each game a team is eliminated, there cannot be a cycle in our subset so our subset is actually a tree (no cycles and every node), to get the maximum result just implement a maximum spanning tree algorithm on the graph.

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    For Silver 3, represent each team as a vertex. Then each edge represents a possible match, with the weight equal to the number of points scored. Note that every elimination tournament can be represented as a tree. The problem is now finding the maximal spanning tree.

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Silver division HINT:

    1st problem: KMP+stack; complexity=O(|S|+|T|); memory=O(|S|+|T|);

    2nd problem: DP; complexity=O((K+R^2)*C); memory=O(R*C); (Alternative solution: DP; complexity=O(R*C); memory=O((K+R)*C))

    3rd problem: MST+prim; complexity=O(N^2); memory=O(N);

    • »
      »
      »
      9 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      On problem 2 how do you do dp in O(R*C)?

      • »
        »
        »
        »
        9 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        It's just partial sum version of O((K+R^2)*C) DP so we can query sum of result from (0,0) to (i-1,j-1) with specific label or all label in O(1) time. 2D partial sum table size is actually R*C*K but we can reduce the table size to just C*K.

        It's O(R*C) by assuming all DP table has been initialized to zero at program start. otherwise it's O((K+R)*C).

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I solved the 1st problem using a linked list to store the text, and deleted each instance of S.

»
9 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится
»
9 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Can someone check my code to Censoring(Silver) please!

It gives RE at 3 tests. I can't figure out where is mistake.

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится
    const int MXN = (int)1e6 + 200;
    

    you must change it to

    const int MXN = (int)2e6 + 200;
    
    • »
      »
      »
      9 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Thanks!

      But I don't understand how my solution exceed bound of array.

      If it is not hard, please explain why!

»
9 лет назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

How have you solved Cow Hopscotch (Gold)?
My solution was O(NMlogNM) but it used a treap and worked for 1984 ms (actually, it passed only after I 'd overloaded operator new).

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    my solution was O(nmlgm).

    I used fenwick for every a[i][j]. (I push indices of columns that have at least on square have a[i][j]), then a dp solve problem.

    maximum time is 300 ms.

    • »
      »
      »
      9 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Alia, can I take a look at your implementation? Maybe with some elaborations please. I had a hard time understanding the official solution.

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Finally I reached GOLD DIVISION :))
Congrats to everyone.

»
9 лет назад, # |
Rev. 3   Проголосовать: нравится +1 Проголосовать: не нравится

Guys, can anybody provide his code for Silver 1 using stack + KMP, please? I have tried for days, but I can't come up with a solution even if I know what I have to use.

»
9 лет назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

Problem Censoring(Gold). My code getting RTE at test 8 ( Only at test 8 ). are there anyone knows why or facing with the same . Here is my code .

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

If anyone still monitors this thread, can you please tell me why my solution to Silver problem one (http://usaco.org/index.php?page=viewproblem2&cpid=529) times out a lot? Here is my code: http://pastebin.com/nUjySfMf I used the KMP algorithm with java, and I'm also removing at constant time.

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Upon deletion, you are going back S.length() spaces and researching. At the worst case it's still O(TS). You need to find a way to memoize so that you don't have to go back S.length() spaces.

    • »
      »
      »
      9 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Sorry, can you tell me what S is and where in my code I go back S.length spaces after deletion? Thanks.

      • »
        »
        »
        »
        9 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        Oh on second glance, it would seem that it is linear time. It's probably because Java is way too slow. My code in C++ passes in 40 ms (at worst).