Изменения рейтингов за последние раунды временно удалены. Скоро они будут возвращены. ×

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

Автор chokudai, история, 2 года назад, По-английски

We will hold HHKB Programming Contest 2022(AtCoder Beginner Contest 235).

The point values will be 100-200-300-400-500-500-600-600.

We are looking forward to your participation!

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

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

Once again, why is problem H called Ex?

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

    Probably means extra, you dumbass.

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

      What's better?

      • A B C D E F G H
      • A B C D E F G Ex
  • »
    »
    2 года назад, # ^ |
    Rev. 3   Проголосовать: нравится +15 Проголосовать: не нравится

    A friend (jokingly) told me it probably stood for, "Extra Garbage Data Structure"

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

    Extra
    Example
    Exercise
    External
    Extended
    Excellent
    Exhausting
    Extraordinary

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

How to solve E efficiently?

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

    Solve offline. Apply normal MST algo for graph with all m normal edges and q query edges combined. The difference is to not actually add the edge if its a query edge. Solution

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

    Store the edges given, in set with ind=-1
    Store the edges of queries, in set with index of query.
    Now apply Kruskal or Prim's and whenever you encounter a query edge check if this edge would have been added or not and store the answer for that index by using vector of strings.
    Finally print that vector.
    Submission

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

    Think of kruskal algorithm used to compute the MST of a graph:

    You sort edges by increasing order of weights and you use an edge if and only if it unites two nodes that are not already connected. So you can put all the edges in the same vector, sort them and keep uniting like if you were computing the MST of the graph.

    At any time when the current edge is a "query edge" you just check if it unites two nodes that are not already connected or not.

    See my code for more details: https://atcoder.jp/contests/abc235/submissions/28547346

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

    My solution:

    Build the MST of the original graph, then the answer for a query $$$(u, v, w)$$$ is Yes if and only if the maximum weight of an edge in the path from $$$u$$$ to $$$v$$$ on this MST is greater than $$$w$$$. So, now our problem has changed to: Given a tree and multiple queries $$$(u_i, v_i)$$$, report for each of them the maximum weight of an edge in the path from $$$u _i$$$ to $$$v_i$$$, which is easily solvable by Binary Lifting.

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

What's the solution to problem F? I've come up with some sort of dp, and I guess it should work, but could someone point out the mistake?

The idea I used is that we can calculate the count of number such that first $$$i$$$ digits match and $$$(i+1)_{th}$$$ one is lower than the one in $$$N$$$. So I've precomputed the number of sequences of length $$$K$$$ for each set of digits using bitmask DP, as well as their sums and later use them in calculations. Here's the code and it's obviously got one issue which is discarding the elements with leading zeros. E. g. 01 is not a valid number for set of digits {0,1}. Can anyone help?

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

    I did some pretty similar DP.

    The states are: number of the digit, bitmask (to know which of the required digits have already been used) and a bool to know if my number if currently less or equal than n.

    Don't allow any leading zeroes (so in your base case don't use digit 0) and at any digit just add a new transition which is "creating" a newer digit already smaller than n:

    See my code for more details: https://atcoder.jp/contests/abc235/submissions/28560145

    Don't mind to tell me if anything is unclear :p

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

    My solution (although I couldn't submit it due to some bugs in my code) is the following:

    Let's say $$$sum(A)$$$ is the sum of all the elements in the set $$$A$$$. Let's also define $$$S_d$$$ as the set of numbers that don't have the digit $$$d$$$ on their decimal representation. Then, we're asked for $$$sum\left([1, n]- \displaystyle\bigcup_d{S_d}\right) = \frac{n(n+1)}{2} - sum\left(\displaystyle\bigcup_d{S_d}\right)$$$. The sum of that $$$union$$$ can be computed by inclusion-exclusion principle: We iterate through all the non-empty subsets of the given digits and for each of them, we can use digit-dp for computing the required sum.

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

Can D be solved with DP? If yes, can anyone share their code?

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

    +1

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

    D can be solved with something not that far from DP. Imagine a graph where each node is a number and you add an edge X->Y if you can reach number Y from number X. You start from number 1 and want the shortest path to get to node N. You have O(n) nodes and O(n) edges.

    Let me know if anything is not clear :)

    Here is my code: https://atcoder.jp/contests/abc235/submissions/28543245

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

    Yes, my very messy solution just uses recursive DP. With a little tweak to avoid infinite circular rotation (if we reach the same state, then bail out and return "infinity"): https://atcoder.jp/contests/abc235/submissions/28563863

    I initially tried to do rotations via integer arithmetic operations, but wasted a lot of time debugging it. Only at the last moment replaced this stuff with string manipulations and got an AC verdict. Premature optimization is the root of all evil...

    Edit: Now hacked by the "99_after_contest_00.txt" testcase :-)

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

Editorial of G:

"(plant 1 or more seedlings to the 1-st garden) and (plant 1 or more seedlings to the 1-st garden) and (plant 1 or more seedlings to the 1-st garden) …"

It this a typo, or what is the meaning of it?

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

Can someone help me with my code for E? It passes sample cases but gives WA verdict. I constructed the mst of the graph and for queries I did the following:

  • if u is ancestor of v, compare w with parent edge of v and the child edge of u that contains v.

  • if v is ancestor of u, same as above

  • compare w with parent edges of u and v.

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

    We could implement logic like "find max weight edge on path from u to v", and if that weight is bigger current query edge weight, then the query edge weight would have been used.

    But to find max weight edge on path from u to v in the MST, we need more that only compare the weight to the parent edge. It can be done in example with binary lifting.

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

Please help me in finding the mistake in E..

Is my approach wrong? https://atcoder.jp/contests/abc235/submissions/28561004

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

Can someone please tell me why I am getting a runtime error on this solution for problem E? I made 6 tries during the contest but wasn't able to find my mistake.

https://atcoder.jp/contests/abc235/submissions/28555671

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

Problem E and F are all classic.

Also E and Link (in chinese) are the same.

Sorry to my poor English.

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

In Question D, I used recursion and it seemed to pass ALL test cases except one. Can anybody guess which test case it would be. Here is my code. Thanks for the help in advance.

Also, There is no TLE or MLE in that test case.

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

My solution for problem E:

Build an MST of the original graph.

Remove all other edges.

Use LCA with doubling technique.

Record the maximum weight of edges on paths of length 1,2,4,8,.....

Process each query independently.

Test if the path on the tree from u to v contains an edge longer than w.

If so answer Yes.Otherwise,answer No.

Code

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

https://atcoder.jp/contests/abc235/submissions/28584413

Can anybody please help me in finding the mistake in my DP solution of problem D .It passed all the test cases except 99_after_contest_00.txt .Even if anyone is able to find that probable case please help me out.

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

    Looks like our solutions were hacked after the contest and mine fails it too (are problem setters reading comments here?). Now it would be indeed interesting to have a look at this 99_after_contest_00.txt testcase. I tried stress testing, but haven't found anything yet.

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

    Now I have some testcases: "2 11327" (expected 40, but got 41) and "2 62153" (expected 17, but got 18).

    The bug is that the solution is effectively doing DFS to find a path from N to 1. But it isn't always the shortest path, so BFS is really needed instead. The original tests used during the contest were weak and didn't detect it. I wonder how many incorrect solutions got accepted?

    And even now, having just a single testcase (testcase 99_after_contest_00.txt) in the set makes it possible for some heuristically tuned or even randomized DFS to be incorrectly accepted.

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

Rank 1 has different coding styles for each problem, how is that possible? chokudai Can you take a look?