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

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

1303A - Удаление нулей

Идея: Roms

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

1303B - Национальный проект

Идея: adedalic

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

1303C - Идеальная клавиатура

Идея: Roms

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

1303D - Заполни сумку

Идея: Roms

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

1303E - Удаляем подпоследовательности

Идея: adedalic

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

1303F - Количество компонент

Идея: Neon

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

1303G - Сумма префиксных сумм

Идея: Neon

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

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

Why this post doesn't have any comments?

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

can someone please explain a little bit about the proof of algorithm of problem F? Why considering all the delete queries in the last doesn't affect the final results?

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

    because the delete queries are after the add queries.

    when considering color $$$t$$$,all the add queries is the queries with $$$c_i=t$$$ ,then for sure,they are consquent,and so for sure all the delete queries are after the add queries

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

      But this is true for a particular color right? Like for a color c what ideally should have been done is to perform add query and then immediately after that perform it's delete queries but in code above they are doing all add first and then all delete query.

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

        No...for a certain color c and all the queries with ci=c,the queries are consquent,so they changed some of the cells into color c.There isn't any delete query between them.After that,some queries may change the color of some cells which were color c,these are the delete queries.

        Like this example:

        2 2 4
        1 1 1
        1 2 1
        2 1 2
        1 1 2
        

        For color 1,the add queries are the 1st and the 2nd while the delete query is the 4th.

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

          Sorry but I think I didn't convey my doubt properly. I am talking about this part of code ..

          forn(i, clrs) recalc(add[i], +1);
          forn(i, clrs) recalc(del[i], -1);
          

          Here we are processing all the delete queries at the end (even after the add queries of same cell i.e. even after add query of (x, y) from c1 to c2).

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

In problem D

If in binary representation of n the i-th bit is equal to 1 and we have at most one box of size 2^i,

I think this should be at least?

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

can someone please explain me about problem B why TotalG = ceil(needG / g) * (g + b) , i don't understand that clearly =)) ????

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

    every (g + b) days have exactly (g) days good, we call it a block. So if we need (needG) days good, we must have ceil(needG / g) blocks, thus TotalG = ceil(needG / g) * (g + b).

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

What is the time complexity for G? nlgnlgn?

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

    Yes. You process each node O(lg n) times using centroid decomposition and each time you do it, you add 2 lines and you make 2 queries for the best path in O(lg n). Total is O(n lg^2 n).

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

Has anyone used adjacency list to solve C ? If so could you share your idea/implementation thanks

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

    Here is my submission — 70873445
    Just store the letter as an undirected graph and make sure that every vertex has degree 1 or 2.
    Then loop through all the vertex and find the vertex which has degree 1 because that would be the start/end of the graph.

    Now go for dfs, if you find a cycle in the graph, that means it's not possible, otherwise dfs will give you the starting letters of the keyboard.

    Then just add the remaining alphabets back in the string.

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

      your code is very messy didnt understand a thing ... or may be I m big big noob

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

The problem statement of F says $$$1 \le c_i \le max(1000,\lceil \frac{2⋅10^6}{nm} \rceil)$$$.

Should not that be $$$min$$$ instead of $$$max$$$?

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

Can someone help me understand why my code for G is TLE on test 33? I've read the editorial and I think I am doing the same thing.

https://codeforces.com/contest/1303/submission/71252477

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

    I had also struggled from test 33, and finally made it accepted.

    I don't know what exactly is test 33, but this test generator code would be helpful. It takes about 20 sec on N=150000 on your code.

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <random>
    #include <ctime>
    #include <queue>
    #include <cmath>
    
    using namespace std;
    
    inline int randint(int a, int b) {
    	return rand()%(b-a+1) + a;
    }
    
    int main() {
    	int n;
    	//cin >> n;
    	n = 150000;
    	
    	cout << n << endl;
    	
    	srand(time(0));
    
    	vector<int> perm(n+1, 0);
    	for (int i=1; i<=n; i++) perm[i] = i;
    	for (int it=n*10; it--; ) {
    		int a = randint(1, n);
    		int b = randint(1, n);
    		swap(perm[a], perm[b]);
    	}
    
    	// sqrt tree, binary tree
    	int sq = sqrt(n);
    	// int sq = 2; // binary
    	queue<int> qu;
    	qu.push(1);
    	int p = 2;
    	while (p <= n) {
    		int a = qu.front(); qu.pop();
    		for (int i=0; i<sq; i++) {
    			cout << perm[a] << ' ' << perm[p++] << endl;
    			if (p == n+1) break;
    			qu.push(p-1);
    		}
    	}
    	/* */
    	
    	for (int i=1; i<=n; i++) {
    		cout << randint(1, 1000000) << ' ';
    	}
    	cout << endl;
    }
    
    

    Use the output of the generator code as the input.

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

      For me, it was a problem from cache. I had used so many random-accessing on arrays, and it became x8 faster when I fixed into a cache-friendly code.

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

        Thanks I may have a chance to fix it now. All my own generated samples ran in <2 seconds

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

can someone explain the solution for problem b

i think it gives right answer for 5 1 5 but wrong for 10 1 10

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

Typo in D, case 2, "most" should be "least".

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

How to proof that D solution is optimal(finds min number of divides)?

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

    we should consider the lowerest bit first , if we don't have the bit , than look for the nearest high bit and decompose it.

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

Hi awoo! Why the scheduled codeforces educational round 83 was deleted?

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

For problem G, how can we get all the "first parts" and "second parts" efficiently?

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

I think there is a mistake in the tests in the B problem. MY solution as well as the tutorial both fail at the same place in the second test. Here is my code: (https://codeforces.com/problemset/submission/1303/79669445)(https://codeforces.com/problemset/submission/1303/79668860). Could someone tell me if there is a mistake

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

    When you calculate minN = round(n / 2), n is truncated before round is called because it's an integer. So n always rounds down instead of rounding up. You can fix this by doing minN = (n+1) / 2 instead.

    Also, it's a little arrogant to assume that the tests are wrong if your code doesn't get AC. Especially if nearly 6,000 others have solved without any issues. So test your code a little on some cases first, before assuming the writers messed up.

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

80808954 Which case am i missing? (Problem B)

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

    you have to take the case when req is divisible by g than you dont need to add the last b days because you have already finished your work and dont and instead of subtracting g from req and than doing other operations better try to do it like this

    ans -> the number of days that we need to calculate

    int n; // length of road
    int nn = (n+1)/2;
    long long req= nn/g;
    if(nn%g == 0)
    {
       ans = req* g + (req- 1)*b;
    }
    else
    {
       ans = req* g + req* b + nn % g;
    }
    ans = max(ans,n);
    cout << ans << "\n";
    
»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

[Deleted]

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

In problem F, can someone please explain the intuition behind deleting cells. How is it similar to adding in reverse order? awoo

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

in D how do we go about the optimality?

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

Alternate dp for E. Let $$$dp[len_{s}][len_{a}]$$$ be the max $$$len_{b}$$$ such that the prefix of $$$s$$$ of length $$$len_{s}$$$ contains non-intersecting subsequences of $$$a$$$ and $$$b$$$ of $$$len_{a}$$$ and $$$len_{b}$$$. Set it to -1 if the prefix does not contain a subsequence of length $$$len_{a}$$$. With this approach we don't have to calculate the array $$$nxt$$$ or make the observation in the editorial. Code 97250299

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

How is solution for D optimal?

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

    Why do people say Educational forces are standard problems ? To me they look nicer problems which nee d to think in screwed up way sorry my native language is not english.Nicer word is "different".Thanks for awoo pointing this out

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

Erasing Zeroes //my solution

include<stdio.h>

include<string.h>

main(){ int t; scanf("%d",&t); char str[101]; while(t--){ scanf("%s",&str); int poslast1,posfirst1,c=0; int l=strlen(str); for(int i=0;i<l;i++){ if(str[i]=='1') posfirst1=i; break; } for(int j=l-1;j>=0;j--){ if(str[j]=='1') poslast1=j; break; } for(int k=posfirst1;k<=poslast1;k++){ if(str[k]=='0') c++; } printf("%d\n",c); } return 0; }

//what's problem in this

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

good

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

In problem G, the value of a path between any two nodes can also be queried using binary lifting. (When you have to compute for upward path, just do it like normal binary lifting. When you have to compute for downward path, "invert" its coinciding upward path using trivial relation between prefix sum and suffix sum)

Implementation