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

Автор xyz2606, 5 лет назад, По-английски
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
  • Проголосовать: нравится
  • +113
  • Проголосовать: не нравится

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

Auto comment: topic has been updated by xyz2606 (previous revision, new revision, compare).

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

constructiveforces

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

Can you also provide codes for the above editorials?

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

Problem D: If we use dynamic programming to compute the shortest path from u with length k how can we be sure that we will come back to u after k steps?

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

Can someone help me with this

Screenshot-20210423-234101

According to what i searched this error means that comparator is broken but i tried my best to include all possibilities in comparator can somebody please help me out in this

Language java Problem B Code https://mirror.codeforces.com/contest/1517/submission/114037412

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

I understand it intuitively but can we rigorously prove that the graph is bipartite?

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

Are there any ways to optimize dijkstra algo for problem D?

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

In problem D, my solution was if I am at $$$(i, j)$$$ then I can go to $$$(i, j+1)$$$ using an edge of weight $$$W$$$ (let's say), and find the shortest path of length $$$k-2$$$ that starts at $$$(i, j+1)$$$ and also ends at $$$(i, j+1)$$$ and then finally return to $$$(i, j)$$$ using the same edge of weight $$$W$$$. So,

$$$dp[i][j][k] = 2*W + dp[i][j+1][k-2]$$$.

Do the same for all of the adjacent vertices, the minimum is the answer.

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

Problem E: How can the case $$$(C/P)CC...CPCPC...PCPP...P(C/P)$$$ be calculated in $$$O(N)$$$? For me the definition of the state looks like this:

  • We have the C/P at the beginning or the end. This is a constant factor.
  • Then we have the CCCCC-Part, the PCPCPC-Part and the PPPPP-Part. To check the sum-condition for all cases we need to iterate over all 3 lengths. the 3rd lengths follows from the 1st and second since their sum is constant.

But that sounds like iterating two lengths and it amounts to $$$O(N^2)$$$? What is the observation that I am missing to make it $$$O(N)$$$?

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

dpforces

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

In D, is not not two dimension more complecated to think about the graph beeing bepartite, and hence does not allow paths of a given parity?

Instead, foreach step we do, we must do a step in the oposite direction. So the number is even.

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

please provide cpde also

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

In problem C could someone help in justifying the second construction ? How to prove that it will always work ?

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

    My approach is also similar to editorial.

    Consider a rubber attached to the point i,i. We want to stretch the rubber p[i] times. So the optimal choice is to stretch the rubber in the following order

    1-Strecth the rubber up

    2-Strecth the rubber left

    3-Strecth the rubber down

    4-Strecth the rubber right

    This ordering will always ensure that we don't have any empty space left. See submission for more details:114016611

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

Video Editorial for problem C: https://youtu.be/RVE8Xprwsfo

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

Hey guys, i found this very strange submission to problem D of this contest (114038234 belonging to the user pxsitivevxbess) and was wondering if anybody could explain to me the logic behind the excessive usage of "ashwet++".

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

Amazing editorial for problem G, the amount of details is simply astonishing

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

    The problem has two types of forbidden pattern: the "square" and the "parallelogram". the square corresponds to 1-0-3-2-1 while parallelogram to 1-0-2-3-1. On the surface, it seems you have to add two kind of edges between rows: 0-3 1-2 (vertical ones) and 0->2 1->3 (diagonal ones)

    But the key observation is that you don't need to, you only need to add edges 0-3 and 1-2. The reason is because to check for parallelogram, you can actually just use the same check: whether a path 0-1-2-3 exists. If such a path exist, then it must either be a square or a parallelogram, e.g.:

    ...10...01...
    ...23...32...
    

    for squares and

    ...10...01...
    ..32.....23..
    

    for parallelograms

    Therefore, we consider the acyclic graph where all "0" nodes have edge to "1" node, all "1" node to "2" nodes, and all "2" nodes to "3" nodes. in this acyclic graph, we want to cut fewest weight nodes so that no path exists from "0" to "3". This can now be done easily using min cut.

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

why in d you need k/2 only.suppose we go to next edge and its cost is 1 but after that costs are 10^6 so why shouldn't i go back and forth only to complete k steps rather than include 10^6 in my ans?

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

    It is not possible.

    Supposition: The optimal cost to travel k/2 steps is C.

    If you move k/2 steps with cost C and if there exist a returning path with length k/2 that has C' < C.Then you can move in the later path to get a cost of C'.But this is not possible because of the supposition.

    Hence we can always travel k/2 steps and return with the same path.

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

      i am asking if suppose i have next edge cost=1 and all edges after wards have cost of 10^6 then why should i go exact k/2 steps in forward direction why not jhust go b/w current vertic and next vertex whose edge has cost 1 and complete k steps in this manner ? why would u inlcude 10^6 in your ans?

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

        You misunderstood my statement.

        Suppose you are initially at $$$A$$$ and after completing $$$k/2$$$ steps you are at position $$$C$$$. So in order to get the minimum answer you must retrace the same path that you have to taken to reach to $$$C$$$ to $$$A$$$.

        That's why we only have to check $$$k/2$$$ steps.

        And steps doesn't mean you have to always move forward. You can also move 1 step forward then backward then forward and so on until all $$$k/2$$$ steps are exhausted.

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

implementForces :)

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

In Problem D, multi-source Dijkstra with a priority queue gets TLE: 114052809.
But if the priority queue is replaced by a normal queue, it gets AC in 405 ms: 114052881.

I think the solution with the queue should get TLE too. But I couldn't come up with an appropriate case. Can anyone try to uphack the solution? Or am I missing something?

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

    For Dijkstra's, the exit condition should be -

    new_code

    instead of

    old_code

    check out my submission, I just modified this line and it passses — https://mirror.codeforces.com/contest/1517/submission/114073092

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

      Actually, both are performing the same purpose here.

      dist[u.r][u.c][u.lv] holds the minimum possible cost for [u.r][u.c][u.lv] till now. So, obviously dist[u.r][u.c][u.lv] != u.w means the value of u.w is greater than dist[u.r][u.c][u.lv].

      Edit: Your submission is passing because of the compiler. I've submitted with != operator using "GNU C++17" compiler and got AC in 1856 ms: 114108137.

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

    By the way, can you explain your logic for Multi-Source Dijkstra's? Mostly why this holds true in this problem?

    Also, the queue solution should be incorrect, because Dijkstra's requires a priority queue for the same?

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

      Logic:
      For a cell (r, c), we need to find the minimum cost after h steps if we start from the cell (r, c). As the graph is undirected, it is equivalent to reach the cell (r, c) from an arbitrary cell after h steps. So, we can do it by taking every cell as the source and calculate the dist[r][c][h] for each cell. It is normal Dijkstra. The rest calculation part for the minimum boredness is quite easy.

      Queue solution:
      Dijkstra needs a priority queue (min-heap) just to reduce the complexity. Taking queue won't make your solution incorrect. In normal graphs, it will increase your complexity.

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

Can you explain the $$$n^2log(n)$$$ solution for problem F? Thanks.

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

    I haven't yet tried, but I guess you can optimize the dp with some heavy-light decomposition trick. I guess, since the number of dp states at node v is of O(depth_of_subree_rooted_at_v), when dealing with node v, you can inherit dp states from the heavy child (child with the maximum subtree depth) and iterate the rest children. That way, you end up with a O(nlogn) dp per radius, then O(n^2 log n) for all radius.

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

hey anyone who can find whats wring in my code of problem B

include<bits/stdc++.h>

using namespace std;

define ll long long int

define el "\n"

define mod 1000000000

int main() { ll t; cin>>t; while(t--){ ll n,m; cin>>n>>m; ll a[n][m]; ll b[n][m]; ll temp=0; vector<pair<ll,ll> > v(m);

for(ll i=0;i<n;i++){
    for(ll j=0;j<m;j++){
        cin>>a[i][j];
        b[i][j]=a[i][j];
    }
  }
  //v[0].first=3;

while(temp!=m){
        ll c=mod;
   for(ll i=0;i<n;i++){
    for(ll j=0;j<m;j++){

        if(a[i][j]<=c){

            c=a[i][j];

           v[temp].first=i;

        v[temp].second=j;
        }

    }
  }
  a[v[temp].first][v[temp].second]=mod;

temp++; }

for(ll j=0;j<m;j++){
   swap(b[v[j].first][v[j].second],b[v[j].first][j]);

}

// cout<<el; for(ll i=0;i<n;i++){ for(ll j=0;j<m;j++){ cout<<b[i][j]<<" "; } cout<<el;}

} return 0; }

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

Help me out with A folks I don't know how to find sum of its digits in decimal representation.

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

    Well, you can prove to yourself that the last digit of "n" is always (n%10) = n modulo 10 (the rest when you devide n by 10. Now, you use a while and at every step you add n%10(last digit) and then devide n by 10 (that eliminates the last digit). You have to do this until n is equal to 0. When that happens you stop the iterration and that's the sum. Hope it was not a joke and I actually helped. :))

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

I haven't understood the editorial of problem E, can anyone explain it in detail?

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

    C and P are two sets of all indexes of "a" (together — "n" elements). Indexes of C is growing wider left-to-right, and P — right-to-left. If for some ci-c(i-1) > 2 than there should be two P's in a row between them. And this means there can't be no more P's to the left from them, and to the right(max — 1), because pi-p(i-1) become 1, and to jump over C it need to become 2 — this breaks monotonic rule. And so on.

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

.

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

Can someone explain Problem B?

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

Can anyone help can't figure out what's wrong with my problem D solution.

WA on Test 5 114051343

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

I really liked the idea for the problem C & D.

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

In prob-D, Can anybody tell the number of states we will have while calculating the shortest path of length K/2 from some vertex u? I think its around K^2 because starting from vertex 'u' ideally, we will traverse in square of K*K size

Update: Got the answer

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

I did try to implement what you have said in B.But somehow its not passing all test cases. Can someone please tell what is wrong with mycode. https://mirror.codeforces.com/contest/1517/submission/114183214

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

please give the codes as well

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

The editorial for problem H says: 'We will explain the precision issues later', but that part seems to be missing. Can somebody please add that part? In my attempts to solve the problem, I struggled with precious issues for quite some time, and I added several hacks until I finally got AC (114778549).

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

Did anyone solve Problem D with Matrix exponentiation?

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

In D how do we make sure that the min steps are coming from same i,j th cell in prev states , in other words how do we make sure after tabulation min of dpijk started from that i j