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

Автор diskoteka, 3 года назад, По-русски

Мы хотим поблагодарить всех участников, кто помог нам и Codeforces впервые преодолеть отметку в 40.000 зарегистрировавшихся пользователей

1862A - Ковёр в подарок

Идея: diskoteka

Разбор
Решение
Оценка задачи

1862B - Игра в последовательность

Идея: diskoteka

Разбор
Решение
Оценка задачи

1862C - Забор в цветочном городе

Идея: playerr17

Разбор
Решение
Оценка задачи

1862D - Шарики мороженого

Идея: diskoteka, Ivang

Разбор
Решение
Оценка задачи

1862E - Коля и кинотеатр

Идея: pavlekn

Разбор
Решение
Оценка задачи

1862F - Волшебство спасёт мир

Идея: diskoteka

Разбор
Решение
Оценка задачи

1862G - Великий Уравнитель

Идея: diskoteka

Разбор
Решение
Оценка задачи
Разбор задач Codeforces Round 894 (Div. 3)
  • Проголосовать: нравится
  • +96
  • Проголосовать: не нравится

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

Есть альтернативное решение задачи C

Заметим критерий симметричности забора $$$a$$$. Забор симметричен тогда и только тогда, когда $$$a_1 = n$$$ и $$$a_{a_i} \ge i$$$ для всех $$$1 \le i \le n$$$.

Давайте докажем этот критерий.

Очевидно, что если если $$$a_1 \neq n$$$, то этот забор не симметричен, потому что забор $$$a$$$ длины $$$n$$$, а забор уложенный горизонтально длины $$$a_1 \neq n$$$.

Нужно понять, что значит условие $$$a_{a_i} \ge i$$$. Понятно, что $$$a_{a_i}$$$ — длина доски, лежащей в $$$a_i$$$ строке перевернутого забора. Чтобы забор совпал с перевернутым, нам нужно, чтобы $$$i$$$ столбец с высотой $$$a_i$$$ находился не дальше, чем конец $$$a_i$$$ доски в перевернутом заборе. А это записывается в точности условием $$$a_{a_i} \ge i$$$.

Пусть забор не симметричный, но $$$a_1 = n$$$. Тогда мы сможем найти строку в перевернутом заборе, которая короче соответствующей строки в обычном заборе, значит не выполнено условие $$$a_{a_i} \ge i$$$. Такая строка всегда найдется, так как все не совпадающие клетки симметричны относительно диагонали.

220214682

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

Code of problem C is giving WA on test 1 and it is written that ai <= n ( There won't be any memory issues since all ai≤n ) but in the problem it is given that ai is upto 1e9

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

is there any proof that the answer for each query in G is the maximum numbers + maximum difference ?? I am struggling to understand it

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

Why there are only 3 comments, even though the edt was published 8 hours ago?

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

If someone prefers video explanations. Here is my Live Screencast of solving problems [A -> F] (with commentary).

PS: Don't judge me by my current rating :(

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

Can anyone explain me the thought process of C, I cannot seem to understand from the editorial :(

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

When will we get the ratings for the problems we've solved? Im new here and just started giving contests so im sorry i dont properly know how things happen and how long it takes

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

    after maybe 5 hours the main tests will run which will take roughly 2 hours to complete, after that it takes another 2-4 hours for the rating changes to update. You can use an extension like cf predictor to predict your rating change accurately.

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

I'm so bad that I only thought of the dichotomy of O (n log n) for problem C. I'm sorry for my poor English

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

220231839 Maybe there is another way to solve D.

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

Cant the problem c sollution be more optimized?;

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

There are many grammar typos in Problem D if someone wants to correct them for future people upsolving it.

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

Why is it giving WA if I use Combination to solve problem D?

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

    Combinatorics isn't entirely wrong, but requires some observations.

    Take the sample of making 179 different ice creams as an example. If we use a combinatorics approach, we find that; 19C2 = 171 and 20C2 = 190

    However, note that the question asks for 179 to be the exact number of ice creams; therefore 190 is in fact incorrect as there are TOO MANY flavours.

    The work-around is the observation that we can increment the number of flavours by 1 simply by doubling up on a same-kind flavour. Thus, we can use combinatorics to find the lowerbound with distinct flavours, and then double up on each flavour until we end up with the correct answer.

    My solution is attached for clarity: https://codeforces.me/contest/1862/submission/220240409

    Note that you must optimise your starting point to prevent TLE

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

спасибо за интересные задачи, но графов маловато)

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

Actually, problem F can be solved using random algorithm, which means you can randomly swap several monsters and defeat them from left to right using water mana first and then fire mana. After approximately 10000 times of attempts, you may pass all the tests, and it runs really fast.

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

    RIP scam failed

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

    Actually, problem F can be solved using random algorithm, which means..

    Hello (from RHEXAOC), don't be upset (too much) about system retesting. I (as well as you) enjoy nondeterministic approaches.

    You basically, changed, so-called, knapsack, which is, taking advantage of natural numbers, to sampling a permutation of monsters. There are too many permutations but the specific projection of that permutations to { yes, no } allowed you to pass preliminary tests. I made a test by myself that your program behaved differently than my program. I would be surprised in other case, that's why.

    As a bonus let me teach you a knapsack, if you wish. Here we, as I said before, take advantage, that a problem is defined on natural numbers. Which allows us to allocate a cell to every sum. So we can store in that sell a maximum cost. In this problem there are no costs just sum.

    bitset<10000 * 100 + 1> btst;
    btst[0] = true; // don't forget (I have had forgotten)
    for (auto a : aa)
        btst |= btst << a;
    

    Now we have bits set on every possible sum. In case you don't see: when we don't take any element, we have all sums { 0 }; than we take an element and we have { 0, a }, then we take the next element and sums become { 0, a, b, a + b } and so on.

    In general case of knapsack, for all possible sums, we store a maximal cost, not just one bit. I guess it is somehow possible to do the opposite (for all costs store something...). You might enjoy a math notation of knapsack problem for some purposes of your own. That's it.

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

My D question is WA9 at C++20, but the code passes when I hand it over to C++17, can any god help me to explain the reason of this condition, thanks!

C++20

C++17

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

Is this round unrated?

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

In D, if x represents 2 balls shouldn't we seek to minimise 2x+y? I am not getting the part with the inequalities:(

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

Can someone tell me why greedy approach doesn't work for F.
The problem breaks down to checking whether all the items can be filled inside 2 bags of different sizes.
Here's what I thought:
- Sort the items by their weight in descending order.
- Iterate over the items array and put them inside the bag which has more space left.

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

Can anyone explain to me the first part of the tutorial of G?

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

    Lets say the sorted array is

    a1 a2 a3

    3 2 1

    As you can see we are adding 2 to a2 and 3 to a1.It means the difference between the adjacent elements is reduced by 1 when we add this AP to sorted sequence. This will go on until the maximum difference between the adjacent elements is reduced to zero. Then we will have same elements and we can remove one element.

    Thus the answer is maximum element + maximum difference.

    Hope it helps !!

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

Can anyone tell me, why Online Judge is giving different output than my local machine for following code:

#include<bits/stdc++.h>
using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned long long;
int mod = 1e9 + 7;


void solve(){
	ull n;
	cin >> n;
	ull x = ((ull)1 + sqrt(1 + 8*n))/2;
	ull count = x;
	ull y = 0;
	if(!(x&1)){
		y = x/2;
		y *= (x-1);
	}
	else{
		y = (x-1)>>1;
		y *= x;
	}
	count += n - y;
	cout << count << '\n';
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);  

    int t = 1;
    cin >> t;
	
    while(t--){
        solve();
    }

    return 0;
}

220249582

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

Hi, in problem F, the knapsack method that is used, wont the number of computations be of the order 10^8, since knapsack is of time complexity O(N*SUM). How is it accepted then?

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

Problem F: Can some one tell me why isn't the tutorial solution giving TLE as it is order of O(sum*n) i:e O(10^8), or am I wrong...

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

[can anyone help me in finding the error in my code of [problem:1862E]] 220407220

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

Problem B,

For b=[4,6,3] why a=[4,6,3,3] is not a valid sequence ?

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

In third question i am getting --> wrong answer Answer contains longer sequence [length = 10000], but output contains 9969 elements. does anyone know how to fix this?

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

how to do E ques by dp (knapsack maybe dp[currIdx][prevIdx][moves_till_now])

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

Can someone please explain as to why commented code is giving TLE for G.

Thanks in advance for the help :).

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

Can somebody explain that dp state in the solution for problem F?

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

Note that the total strength of the monsters is given to us. Therefore, it is enough for us to spend as much of the available water mana as possible, so that there is enough fire mana left for the remaining monsters. This is a well-known knapsack problem.

Can anyone tell me which well-known knapsack (variation) this is?

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

    0-1 knapsack.

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

      Can you please explain why is it a 0-1 knapsack.
      Where are weights and capacities etc. which are parts of knapsack.
      I can't understand.
      Also, If possible suggest some resources(problems) to learn these types of implicit knapsack.

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

        The total sum of the monsters' strength is the knapsack' s capacity. Each strength of the monster is both its weight and capacity.

        Then in my first solution(220277552) which is MLE dp[i][j] means The maximum amount of capacity that the first i monsters can occupy without exceeding the capacity j.Then I used scrolling array optimization in my second solution(220282293) and AC.

        Then we can get a set including the sum of the strength by selecting any number of monsters from all and adding their strength together.

        Then we can enumerate all the divisions of the sum of the strengths of all monsters into two parts, and use the set we just got to judge whether it can be divided in this way, and constantly update the least amount of time, that is, the answer.

        I don't have good advice on the specific problems of some implicit knapsack, you can search the Internet to find them.

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

can someone explain the TC of problem F.

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

problem G is bad because of its TL and n = 1 case

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

I misunderstood problem C. In this problem, for a very long time, I was stuck by calculating the total no of diff balls that are required to get different pairs>=n. I was considering that to be my answer, but here I was asked to calculate the minimum no of balls required to get exactly n different ice-creams not more than that. So for this using binary search I calculated the minimum no of different balls required to get the different pairs>=n. Let's say I got res if (res*(res-1))/2==n then this res will be my final answer. Otherwise, I need to do some manipulations. I will go do res--, now this res will make less no of pairs than n find out how much n exceeds this, assume it to be temp. We will be requiring this difference many balls. Hence, in this case our final answer will be (res+temp).

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

Задачи легкие!!!!! но некоторые понять сложные!!!!!