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

Автор awoo, история, 2 года назад, По-русски

1923A - Moving Chips

Идея: BledDest

Разбор
Решение (BledDest)

1923B - Monsters Attack!

Идея: BledDest

Разбор
Решение (Neon)

1923C - Find B

Идея: Roms

Разбор
Решение (Roms)

1923D - Slimes

Идея: BledDest

Разбор
Решение (Neon)

1923E - Count Paths

Идея: BledDest

Разбор
Решение (awoo)

1923F - Shrink-Reverse

Идея: adedalic

Разбор
Решение (adedalic)
  • Проголосовать: нравится
  • +62
  • Проголосовать: не нравится

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

I think E has same idea as this

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

Problem C video Editorial : YOUTUBE VIDEO LINK Audio : English

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

E can be solved linearly.

edit : I lost some rating but I think the problems were very nice :)

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

Wow, I just see a solution of E which takes $$$O(n)$$$ time. It just uses 1 DFS to calculate the result synchronously just by how we will do to find out the result of one color.

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

I solved E with centroid decomposition (which is $$$O(n log n)$$$) but got TLE.247977712

But the Editorial says authors were expecting $$$O(n log^2 n)$$$ solutions. I'm confused.

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

Hello Codeforces! Please explain what virtual trees are (they are used in the second solution of the problem E).

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

Need Help.

Why does this solution give tle while the one given in editorial passes for the problem 1923E - Count Paths.

248160733

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

Can someone please tell on which case this is failing?

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

I had an idea that works in O(n):

Check this code:

https://mirror.codeforces.com/contest/1923/submission/247999826

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

i have solved E linearly. Here is the solution

here ans[c] means how many visited nodes of color c are available to be the first vertex .

when we are going forward we can only add 1 node of that color with new node. And when we go backward we are getting 1 extra node to add with new nodes.

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

In problem B, why is it always optimal to hit the nearest monster? There can be a possibility that there was another monster far away with much much greater health, and if certain bullets were not provided to them within the starting seconds, they would definitely hit the origin.

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

You can use divide and conquer on tree to solve problem E easily in $$$O(n \log n)$$$ too. It is easy to think.

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

If someone want to consult a centroid decomposition + set solution can see my submission: 248033502. My idea: I can count the number of way cross the centroid node for all node and use set to manage the first node in DFS way has color C.

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

I am unable to understand why the solution to problem E has time complexity O(n log^2 n ). For every node, we are iteration through all the children, and then for every child we are iterating through every color it has. Can someone explain it to me?

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

My solution for C got hacked. It seems somes python solutions are just taking more time. Can somebody explain ?

def f(c,l,r):
  if l == r:
    return False
  return c[r]-c[l-1] >= 0

def solve():
  n,q = list(map(int,input().split()))
  a = list(map(int,input().split()))
  b = [ -1 if x == 1 else x - 1 for x in a]  
  
  c = [0] 
  for i in range(n):
    c.append(c[-1]+b[i])

  for i in range(q): 
    l,r = map(int,input().split())
    if f(c, l, r): 
      print('yes')
    else:
      print('no')

   
t = int(input())
for _ in range(t):
  solve()
»
2 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

About F's fact 4, two binary strings should have same number of '1'. Is it true?

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

    If $$$s1=s2$$$, there will be same number of $$$1$$$'s. Otherwise, $$$s1 \lt s2$$$ or $$$s2 \lt s1$$$, and they don't have the same number of $$$1$$$'s. The same relationship will hold between $$$s1'$$$ and $$$s2'$$$ since the fact mentions that we are replacing the same number of $$$0$$$'s with $$$1$$$'s in both strings.

    For this problem though, $$$s1'$$$ and $$$s2'$$$ will always contain the same number of $$$1$$$'s. But this condition is not necessary for $$$s1$$$ and $$$s2$$$.

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

I solved E using stack for each color.

Here is my solution: 248216745

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

D was a realy good question. Great Contest

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

248285844 Problem D Whats wrong with my code please someone help. I just don't get why am i getting wrong answer.

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

For Problem E, I came up with this simple solution.

void dfs(int s, int p, vector<int> *adj, map<int,int> &m, ll &ans, vector<int> &a){
    ans += m[a[s]];
    int t = m[a[s]];
    for(int u:adj[s]){
        if(u==p)
            continue;
        m[a[s]]=1;
        dfs(u,s,adj,m,ans,a);
    }
    m[a[s]]=t+1;
}
// not pasting template here, scan -> cin, print -> cout
void solve()
{
    int n;
    scan(n);
    vector<int> a(n);
    vscan(a);
    vector<int> adj[n];
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        adj[x-1].push_back(y-1);
        adj[y-1].push_back(x-1);
    }
    map<int,int> m;
    ll ans = 0;
    dfs(0,-1,adj,m,ans,a);
    print(ans);
    return;
}
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can we solve C using sparse table ?

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

can we solve C using sparse table ?

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

Can someone explain why jiangly's solution to problem E works in O(Nlog^2N). I know it utilizes small to large merging, but why does merging by the size of color sets yield that complexity? When we merge some node's children, set size won't necessarily go up 2x. For example combining sets (1,2,3) and (1,2,3) will give us (1,2,3) again, so the regular proof does not apply here.

Edit: Nvm, I neglected the fact that number of colors is always less or equal than the number of nodes in a subtree. The proof is trivial.

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

I do not understand why does my submission not pass the second test case and what am I doing wrong here. Can someone please explain? 248388078

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

I made video editorial for E discussing the DP idea (excluding the small to large trick).

I also made a contest with easy version of problem E and some followup problems. Access it here

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

Problem F's "Fact 4",You should specify that s'1 and s'2 have the same number of 1s , otherwise your statement is wrong.

s1=1000011 s2=1000100 k-1=2 s'1=1001111 s'2=1000111 s1 < s2 and s'1 > s'2

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

For E with Virtual Trees — I think you can do just an modified Euler walk of the tree first, and then walk on only the nodes of the same color in the order of the Euler walk: it will be eqv. to doing DFS on the Virtual Tree. So should be easy to do DP in each node for all its top-level children with/without being a direct descendent of the parent.

The final complexity should be just O(n), better than the O(n log n) of the tutorial.

The modification of the walk is that you put the node each time you visit it, not only first & last time.

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

How Can We Do Problem B using Dynamic Programming?

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

How can we do B using DP?