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

Автор Stepavly, история, 6 лет назад, По-русски

1282A - Temporarily unavailable

Идея: MikeMirzayanov Разработка: MikeMirzayanov

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

1282B1 - K for the Price of One (Easy Version), 1282B2 - K for the Price of One (Hard Version)

Идея: MikeMirzayanov, unreal.eugene Разработка: Supermagzzz

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

1282C - Petya and Exam

Идея: AdvancerMan Разработка: Supermagzzz

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

1282D - Enchanted Artifact

Идея: unreal.eugene Разработка: unreal.eugene

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

1282E - The Cake Is a Lie

Идея: MikeMirzayanov, AdvancerMan Разработка: AdvancerMan

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

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

Could anyone explain why the problem D answer for the below case is 1?

6 17 2 6

0 0 1 0 0 1

7 6 3 7 10 12

When can the student leave to get 1? If the student leave T=6, he can solve 3th problem, but the 2th problem makes his score 0. Am I missing something?

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

Solution to problem B is not very clear yet. Can someone please explain it in little more detail?

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

    Sort the items by price. Let us say we wanted to buy only all of the first i items by paying the minimum price possible, call this minimum price needed dp[i].

    If i >= k-1 (0 based index).

    We will definitely have to buy the most expensive item but on purchasing that we can get items from i-k+1 to i-1 for free.

    So dp[i] = cost of item i + dp[i-k]. If dp[i] <= budget, our answer is atleast i+1.

    If i < k-1 the case is simpler, check the code for this case.

    Also if there are n items on sale, there is no point of purchasing an expensive item but leaving out a cheaper one. In essence if you buy some ith item you will definitely buy first i-1 items also. Let me know if you'd like a proof for this too.

    https://mirror.codeforces.com/contest/1282/submission/67533829

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

My solution for problem E is similar but definitely much shorter, the main idea is to take an arbitrary triangle to remove it and recursively solve on the three sides, I have a list with the order of vertices and other for the order of triangles, in my recursive function I have a fixed side(edge) then I find one arbitrary triangle with that edge and solve similarly for both sides

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

I have another approach for $$$D$$$.

Assume length of $$$s$$$ is $$$l$$$. First, query with $$$t$$$ = "a" and let the response be $$$r$$$. There are 2 cases:
1- string $$$s$$$ consisted only of "b" letters, then $$$l = r$$$.
2- string $$$s$$$ had at least one "a" in it, then $$$l = r + 1$$$.

Now query with $$$t$$$ of length $$$r$$$ consisting only of "b" letters and let the response be $$$e$$$. If $$$e = 0$$$ then terminate, otherwise, You have 2 pieces of information:
1- $$$l = r + 1$$$.
2- The distance between string $$$s$$$ and string full of "b" letters of length $$$l - 1$$$ is $$$e$$$.
3- $$$s$$$ has at least one "a" in it.

Now, let $$$t$$$ be a string of length $$$l$$$ of only "b" letters. The distance between $$$t$$$ and $$$s$$$ is also gonna be $$$e$$$ (I think the only case where this is not true if string $$$s$$$ consists only of "b" letters, which we know it already doesn't. Would love a proof for this tho).

Now just like the rest of the solution in the editorial, iterate over $$$t$$$ from $$$1$$$ to $$$l$$$ and try to turn the character to "a" and query. If the distance in the response is less than $$$e$$$, then update $$$t$$$ and $$$e$$$. keep doing this until the response is $$$0$$$

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

For the question, Price of one easy version i tried to solve it using modification of knapsack but it gave tle on pretest 3. Did i miss something, code is as below:-

private static int getMem(int[] a, int n, long w, Map<String, Integer> map) {
    StringBuilder sb = new StringBuilder();
    sb.append(n).append(":").append(w);
    String key = sb.toString();
    if (map.containsKey(key)) return map.get(key);

    if (n <= 0 || w <= 0) {
       map.put(key, 0);
       return 0;
    }
    if (a[n-1] > w) {
       int value = getMem(a,n-1,w, map);
       map.put(key, value);
       return value;
    }
    else {
       int d = Integer.MIN_VALUE;
       if (n-2 >= 0 && a[n-1] <= w) {
         d = 2;
       }
       int val = max(1+getMem(a,n-1,w-a[n-1], map), getMem(a,n-1,w, map), d+getMem(a,n-2,w-a[n-1], map));
       map.put(key, val);
       return val;
    }
}
  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 3  
    Проголосовать: нравится 0 Проголосовать: не нравится

    You can optimize this to linear time, since the values of all of the items are equal. For example, since an item with cost 10 and another with cost 5 are always equal value, you always want to take the one with the smaller cost.

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

In solution to problem B, the sort function is used which takes o(n*log(n)) time complexity. So how come the solution has linear time complexity? Please explain!

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

Someone Please Help me Correct my Solution For Problem B. I am unable to find which case I am missing . It would be of great help. My Solution :- (https://mirror.codeforces.com/contest/1282/submission/67578229)

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

Could anyone explain problem B in more detail

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

My submission for C giving WA. Someone please help!! Edit:: I think I got my mistake..

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

B1 easy version

include<bits/stdc++.h>

using namespace std;

define ll long long

int main() { int t; cin>>t; while(t--) { ll n,p,k; cin>>n>>p>>k; ll arr[n]; for(int i=0;i<n;i++) cin>>arr[i]; sort(arr,arr+n); ll cnt=0; ll val=p,l; int f=0; for(int i=0;i<n;i++) { if(p>=arr[i]) { val=p; p=p-arr[i]; cnt++;

       l=i;
    }
    else if(val>=arr[i])
    {   val=val-arr[i];
         cnt++;
    }
    else
    {
       break;
    }
}
//cout<<val<<endl;


    cout<<cnt<<endl;
}
return 0;

}

why my code is giving wrong ans .

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

    1) Check the language setting of your comment -- it does not show up in English version of the website.

    2) Please, do not paste the code in the comments, use [submission:67556497] instead. If it is a small piece of code, use "block" style (or manually surround the snippet with ~~~~~).

    3) Look at the test case output. It says wrong answer 26th numbers differ - expected: '4', found: '3', meaning that you fail the 26th test in the second test case. Find that test and go through your algorithm with it. Do what you can before asking others, this will help you to realize why your are wrong next time you come up with a similar algorithm.

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

In problem C, why is the answer of this testcase $$$1$$$ ?

1
6 17 2 6
0 0 1 0 0 1
7 6 3 7 10 12
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For the first problem(temporarily unavailable) in the fifth test case a=-10 b=20 c=-17 r=2 , the coverage will be from [-15,-19].so a to b must added, the answer must be 31, if I'm wrong case someone explain why I'm wrong.

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

Please find the error in my code i don't know what's going wrong here My Submission for Problem D

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

For Problem B. first sort all the goods by its price.and take this array as p[]; then let f(x) means the least money he should pay to buy first x goods. so if x <= k , f(x) = f(x-1) + p[x] if x > k , f(x) = min(f(x-1) + p[x],f(x-k) + p[x]) // use offer or not then iterater all the f(x),find the most x satifies f(x) <= the money I have. does I make this problem more complex?

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

Задачу B можно решить одномерной динамикой, если считать, что dp[i] — минимальная сумма, за которую можно купить i подарков. Потом можно просто перебрать массив dp и вывести такой индекс i, что dp[i] <= p и i максимален. И да, для него тоже нужно сортировать массив.

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

problem b order is $$$O(N^2)$$$ ?

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

can someone explain C approach briefly?

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

In tutorial of problem 1282D - Enchanted Artifact:

Consider an arbitrary string $$$t$$$ of length $$$l$$$ and let the answer to its query be $$$q$$$. Then if we replace the letter $$$t_i$$$ with the opposite one (from a to b or from b to a), then we may have one of two situations:

  • $$$q$$$ decreased by $$$1$$$, then the letter $$$t_i$$$ after the change coincides with the letter $$$s_i$$$.

  • otherwise the letter $$$t_i$$$ before the change matches the letter $$$s_i$$$.

I think that this is not truth. For example:

$$$s=$$$ abababababababababab

$$$t=$$$ babababababababababa

Edit distance is $$$q=2$$$ (delete the first character and insert the last one).

Let's replace some a in the middle with b (the letter $$$t_i$$$ after the change coincides with the letter $$$s_i$$$):

$$$t'=$$$ bababababbbababababa

Edit distance is $$$q'=3$$$ (replace this letter, delete the first character, and insert the last one).

The letter $$$t_i$$$ after the change coincides with the letter $$$s_i$$$, but $$$q$$$ didn't decreased by $$$1$$$.

Am I right?

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

Could anyone explain why the solution of problem C answer for the below case is 2?

3 5 2 100

0 0 1

5 5 5

If student leave at 5, he must solve all the problem. Am I misunderstanding?

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

can someone please explain me 8th no test case of 1282C — Petya and Exam if he do the first problem then s=6 which is equal to next ti,so then he have to do next problem because it became mandatory then, so how the answer is one,it should be zero my solution is 67599856

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

explain test case no 8 of 1282C — Petya and Exam how it is 1 it ans should be zero

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

I am getting WA on test 2 on C.

https://mirror.codeforces.com/contest/1282/submission/67600070

Can Someone Please Help.

Thanks

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

Based on your editorial of problem E, I think one can do simpler things to solve the problem:

  • To find $$$q$$$, consider the fact that whenever we cut off a triangle, we lose a vertex, i.e., it no longer appears in any further triangles. So, simply maintain the frequency of all the vertices (the no. of triangles it appears in) and also the triangles that contain the $$$i$$$-th vertex. At every step, choose a vertex that has a frequency of $$$1$$$, and cut its corresponding triangle.
  • To find p, consider every triangle. It has $$$3$$$ edges. Since only a single edge corresponds to the vertex of the polygon, and it appears only once in the input, we construct a graph on n vertices. We compute the count/frequency of all the edges in the input and for all edges $$$(u - v)$$$ that have a frequency of $$$1$$$, we add an edge $$$(u - v)$$$ in the graph. Now, the graph will be in the form of a simple cycle corresponding to the order of the vertices in the polygon. So, simply perform a dfs to find $$$p$$$.

Here, we have found $$$p$$$ and $$$q$$$ independently.

Code: 67604806

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

I dont get why the answer to test case 8 of problem c is 1 and not 0. In that test case the problem with lowest mandatory time is the third one, so if we want to solve one or more problems we must solve this one, but because the time it takes to solve this problem is 6 seconds, and there is a problem which its mandatory time is 6, we can not solve the third problem without solving this one or getting a zero score.So why is the answer to this test case 1? I am probably missing something here but i cant figure it out. Can someone please help me? edit* I found out how it can be 1.

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

queryforces

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

My soln. is similar to one which is mentioned in editorial and it is passing for problem B1 but failing for problem B2. I am not able to find out the mistake. Please help.

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

please, can anyone tell me that why in b2 editorial solution first loop run upto only k ? why ? please, anyone reply guys.

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

For me personally, finding permutation of vertices was far easier than finding an order of cuts.

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

Do I have correct idea for problem E?

https://mirror.codeforces.com/contest/1282/submission/67669011

Idea:

Store vertices like graph. 1 piece = 6 new edges. Sort vertices by number of neighbors. On each step poll vertex V with smallest number of neighbors. V must have only two neighbors. Delete V from its neighbors. Add these two neighbors back to priority queue. Repeat while there wont be only two vertices.

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

Why does the link to the editorial of this round appear twice? https://mirror.codeforces.com/contest/1282

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

Can someone figure out what's wrong with this solution for D? 67670033

It has a similar idea as given in the tutorial.

unreal.eugene

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

Nice testcase 67 in D.

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

-3 1 2 0 how is the answer to this query for problem A 4?shouldn't it be 5? while travelling : -3 -2 -1 0 1 ,nowhere is tower signal available.

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

Could anyone help me to see why I got RE? TIA! 68362298

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

I doubt that the checker of Problem D calculates incorrect Edit Distance when $$$|t| \gt |s|$$$ because 68363205 got WA on test 1. Can anyone help me about this? Thanks.

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

can someone explain the algorithm to problem B2

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