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

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

We will hold AtCoder Beginner Contest 188.

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

We are looking forward to your participation!

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

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

[After contest]

How to solve D?

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

E was easier than D . How to solve D and F ?

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

    To solve D, I use Sweep-Line algorithm

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

    for D I use coordinate compression,

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

      I understood the sweep-line solution , Could you please explain how coordinate compression can be used to solve the problem ? Or share your submission ?

      If it's similar to the one given here isn't it same as sweep-line ? We are adding and subtracting from index (which are mapped to larger values and thus it can be said that they are "compressed") but it's same as adding and subtracting in map and traversing through it.

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

    D seems pretty standard iteration over all discrete point boundaries and since for each range the minimum answer is the same for each day, we can add its range * minimum answer for the range to the final answer.

    For F, I came up with this solution : Decide how many multiplication operations one will use (iterate on it, because it's max around log2(y/x) +- 2, say 'i' is the pointer). Now if we use these many multiplications, subtract contribution of original value * 2^(i) from the final required value. Now take the absolute value of the difference. We now need to arrange subtraction and addition operations in the original multiplication operations so as to make difference = 0 while minimizing total operations. Here we an observe that if we move optimally, there are at max 2*i + 1 distinct values that will be assumed by the difference if we start reducing from the highest bit. You can understand it like this : We either just reach the particular value or just exceed it using our difference operations at every bit. It doesn't make sense to go too far from the given difference. We can find these by taking modulo of difference, say m, with (2^j) making m and (2^j) — m as the optimal values for all j from 0 to i. Now we can run a dynamic programming from these values to get the minimum answer for i as dp[difference] + i. Minimum over all i is the required answer.

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

How to solve problem D?

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

    Push the start/end of each service into a priority queue sorted by day, go from lowest to highest, keep track of current sum of separate fees and you can calculate Ans += min(sum, prime fee) * elapsed days

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

    Put beginnings and ends into one array and sort by their time (keep track to which interval they belong to and whether they are start/end of the interval). Then scan along this array and compute the current price for one day. This price holds for the whole interval from the current processed event (beginning/end of interval) to the previous event. Of course, instead of this price, we can choose the price C (the whole subscription). So we add the chosen price multiplied by the time since the last event to the result.

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

how to solve F?

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

Can someone tell me if what I'm doing for F here is right or wrong? I'm passing 48 out of 49 cases

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

I am getting one test case wrong in D. My Code Please let me know that case.

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

Anyone please help me in my submission of E my submission

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

I tried my best to solve E, but I can't. Can anyone give me a hand?

Here's my submission

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

Only one test-case is failing for D, can anyone figure out the mistake?

https://atcoder.jp/contests/abc188/submissions/19339643

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

C was very easy but , question statement was very confusing , am i only who feels like this or really it was confusing.

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

For E, I tried finding the maximum value in subtree of a node and tried that value with current node value. Why is it wrong? Can someone explain please?

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

I ignored in E that Xi<Yi, so I tried to implement using bfs (and dfs, too).

The idea is, to find the minimum possible buying price foreach vertex, and collect the max diff of each vertex price minus the minimum price. But that failed for all implementations. What is wrong with that aproach?

Example, dfs: https://atcoder.jp/contests/abc188/submissions/19357783

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

Can anybody give a test case for which my solution is failing. It is failing only on one test case (random_25) Link Edit: Found the mistake (interval * hope[i].second was too big to fit in long long

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

Solution for D :

Like we do Range update query on array in O(1) Reference We will apply this thing using a map because we can't take array as constraints are big for array size.

My Solution

We increase the m[start[i]] with c[i] and decrease the m[end[i]+1] with c[i] so as if we traverse from the start we can take sum of values in m. We will store the previous day as you can see in my solution. So now our question comes to whether we will take subscription or not for days=it.F-prev.F.

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

Solution for E :

My solution

For each node we store a high[i] ( it represents the highest a[i] in the cities reachable from i). We can do this using simple DFS. Now for each city we can take current city as the city where we buy our gold and in high[i] we have the city that is reachable from current city, we will sell at the city that has maximum value. We will now take all cities and their child cities and update our answer as ans=max(ans, high[it]-a[curr]).

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

My E is failing on two test cases. Can someone help me? Submission

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

    ckmax(maksi[s], a[s]);

    You assume that you can sell at the same city as you bought, but that is not the case, you can only sell in another city.

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

      I think I considered that case. I "split" the graph into two parts such that somewhere in the left part we bought gold and somewhere in the right we sold gold. I split the graph on the edges. (Left part is the left side of the graph when we delete the edge and the right part is the right side of the graph when we delete the edge.)

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

        You maintain two dps, max price per vertex you can get if bought at that vertex, and min price you can have paid if sell at that vertex.

        But for both dps you must not put a[i] at position i into mini[i] or maksi[i], because you cannot sell for a[i] if you have bought at i.

        Does the third example works with your code?

        And btw, you do not need that "split". The max/min diff you find in one of mini or maksi you will also find in the other one. It is enough to check the max selling price or min buying price foreach vertex, no need to check both.

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

          Yeah, the third example works with my code. You got my dp definition wrong. I defined dp (mini) as the minimum value we can get if we "split" the graph at the current node (including and that node). That dp is the left side. The same goes for maksi, but it shows the maximum value. This is the right side. In the end, I overcomplicated my solution, but I am trying to find the mistake. Thank you for trying to help me.

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

For F I understand that if y is even and the optimal answer is going to have a division operation then it is optimal to perform division right now. If y is odd then try both y-1 and y+1. It suggests that after at most 2 operation value will be halved. This way the height of the recursive tree will be log(y)=~60

I tried a few examples and it seems the number of states at each height is not growing very fast because of collision

Is there any tight upper bound for the number of states at each height and overall states in the tree?

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

My Submission

For problem E

I think of it as a DAG

And then dp on top

Why is my solution incorrect

Is there anyone who can help me

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

I found a counterexample to my accepted code (https://atcoder.jp/contests/abc188/submissions/19346819) for F.

On test case "1 1243", my accepted code prints 16, but the correct answer is 14, as witnessed by the following path: "(((1*2*2+1)*2*2*2-1)*2*2*2-1)*2*2-1"

The issue is that my code does not correctly compute the shortest way to make a number using positive and negative powers of 2; I thought the only issue is that you can replace blocks of ones with 2 operations (a positive and a negative power) but actually the situation is more subtle...you can make 11011011 with only 4 operations (not 6)

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

Why is this algorithm not working? Problem — D

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

I did the D problem base on the tutorial. and instead of using

	for (int i=0;i<n;i++)
	{
		cin >> a[i] >> b[i] >> c[i];
		mapp[a[i]] += c[i]; mapp[b[i]+1] -= c[i];
		s.insert(a[i]);s.insert(b[i]+1);
	}
	d = vector <long long > (s.begin(),s.end());
	long long temp=0;long long res=0;

I use


for (int i=0;i<n;i++) { cin >> a[i] >> b[i] >> c[i]; mapp[a[i]] += c[i]; mapp[b[i]+1] -= c[i]; d.push_back(a[i]);d.push_back(b[i]+1); } sort(d.begin(),d.end());

i thought it was right but somehow i got WA for 15 testcases pls help :<

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

can any one help me in finding my mistake in problem E peddler?? here is my solution https://atcoder.jp/contests/abc188/submissions/19482465

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

Can someone help me? I am trying to solve E with DFS+DP of maximum selling price, but I keep getting WA, and I can't figure out why. thanks in advance.

https://atcoder.jp/contests/abc188/submissions/22161551

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

How can we solve the variant of D if there is a condition that Snuke Prime can be bought only for one fixed interval? In other words, if Takahashi cancels his subscription on some day, then he cannot resubscribe.