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

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

1506A - Странная таблица

Автор задачи: sodafago

Разбор
Решение

1506B - Частичная замена

Автор задачи: MikeMirzayanov

Разбор
Решение

1506C - Двусторонние строки

Автор задачи: MikeMirzayanov

Разбор
Решение

1506D - Эпическая трансформация

Автор задачи: MikeMirzayanov

Разбор
Решение

1506E - Восстановление перестановки

Авторы задачи: MikeMirzayanov

Разбор
Решение

1506F - Треугольные пути

Автор задачи: MikeMirzayanov, Stepavly, Supermagzzz

Разбор
Решение

1506G - Максимизируй оставшуюся строку

Авторы задачи: MikeMirzayanov

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

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

Problem C was a direct Longest Common Substring question

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

Nice problems. Thanks for such a wonderful contest.

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

very interesting tasks!

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

Spoilers are broken for me.

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

tutorial d is not clear

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

Please put the code in spoiler tag.

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

Hey, MikeMirzayanov Just wanted to bring before you plagrism of two users

cyborg_7459 and cyborg7458

Both of these Users don't know whether same persons or different has submitted solution of Problem A and B with minor Changes. Please Do look at their submission. Even their template is same. Since Even submitting Solutions from alternate account is clear voilation of policy please Review their submission. Maybe they would be same person just submitting solution from one account to confirm its correctness and escape penalty, which is voilation of Rule and needed to be punished if really found guilty.

Their Submissions:

Problem A: 110996666 and 111008607

Problem B: 111007814 and 111006918

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

    MikeMirzayanov plag_report Yeah my bad, but I have an explanation for that which I think might be justified. Since the past 3 contests I've been facing issues with the CodeForces server being down, as might be evident from the bad results of my past 2 contests as well as the fact that I could not give the Division 2 immediately preceding today's contest. Thus, to prevent a negative effect on my rating I started today's contest with my alternate account but switched back to my original one after facing no issues for about half an hour.

    I had no idea that submitting from 2 accounts is also a violation of Rule, and I thought that since I could easily prove the 2 accounts to be mine, I would be able to show that the code is completely original in case someone said otherwise.

    I can assure you that it wasn't a case of trying to avoid a penalty because I did get penalties in my D and E as well. If I had been trying to avoid penalties by testing solutions with my alt account, then I obviously wouldn't have stopped that for the harder problems

    Moreover, I submitted the solution for A from my main account 15 minutes later, which covers up the 1 penalty advantage that I would've received in problem B

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

my solution for D

sorry for my english

let MAX be the maximum number of times a number occurs.

if MAX>n-MAX, then the answer is MAX — (n-MAX) because we can delete this number with all the others, but we can't delete it with ourselves.

otherwise, the answer is n%2, because we can delete the remaining numbers up to the number of our number, and then delete them with our number. well, if n%2 == 0, then we can delete everything, otherwise it is clear that we will not be able to delete one element because we delete 2 elements each

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

    how can we prove if n%2 == 0 and MAX<=n-MAX then every number will get paired up

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

      you can easily prove this by induction.

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

      Sort the array and pair up $$$a_i$$$ with $$$a_{i+n/2}$$$. Since every number appears no more than $$$n/2$$$ times, these two numbers are always different.

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

      Prove by contradiction-> Let there be some numbers left. Without loss of generality, we can assume that there are x 1's left. Let's assume initially there were y 1's present in the array. So, we can safely say that (y-x) 1's were paired with some numbers. So, there are $$$n-y-(y-x)$$$ elements left which are neither 1's nor paired to any 1. So, there were $$$\frac{n-y-(y-x)}{2}$$$ pairs involving no 1. So, we will try to break $$$\frac{x}{2}$$$ of those pairs and pair each number with the remaining $$$x$$$ 1's. Now, we just have to prove that $$$\frac{x}{2}\leq\frac{n-y-(y-x)}{2}$$$.

      $$$x\leq n-y-(y-x)$$$
      $$$2*y \leq n$$$

      Now, as the most frequent elements occur less than $\frac{n}{2}$ times, so this condition is satisfied. Hence proved! Voila!

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

      Since now MAX <= n-MAX, you could pair numbers in n-MAX. Whenever you delete a pair, n-MAX => n-MAX-2. Continue this process until MAX == n-MAX-2*pair_nums.

      [Noticed that there must a pair_nums which fits the equation. If not, then there is a number which appears (n-MAX-2*pair_nums) times and MAX < (n-MAX-2*pair_nums), however MAX is the max appear times.]

      Then we could delete each number in MAX with others.

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

Learnt something new today — s.lower_bound(x) is MUCH MUCH faster in set than lower_bound(s.begin(),s.end(),x). Wasted an hour and will cost me my rating but definitely wont make this mistake ever again. Thanks :)

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

VideoTutorial of problem (B + C) link : https://www.youtube.com/watch?v=wfmIZ6XgfTY

HAPPY CODING

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

I guess problems were easier than the editorial :)

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

Can anyone please explain the problem 1506G — Maximize the Remaining String in simpler way?

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

Stepavly for problem E, i think u forgot to mention approach for lexicographically maximal string. I cant find it

"If we want to build a minimal lexicographic permutation, we need to build it from left to right by adding the smallest possible element. If q[i]=q[i−1], so the new number must not be greater than all the previous ones, and if q[i]>q[i−1], then necessarily a[i]=q[i]. q[i]<q[i−1] does not happen, since q[i] — is the maximum element among the first i elements.

We get a greedy solution if q[i]>q[i−1], then a[i]=q[i], otherwise we put the minimum character that has not yet occurred in the permutation."

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

    To get the maximum you can do something very similar.

    If q[i] > q[i-1], again we have q[i] = a[i]. When this happens, add all integers between q[i-1] and q[i] to a maximum priority queue. For elements where q[i] = q[i-1], a[i] is the element at the top of the maximum priority queue.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится
If c1=c2, then if (r1+c1) is even, then the cost is r2−r1, otherwise the cost is 0;

Shouldn't that be $$$r1 - c1 = r2 - c2$$$ instead of $$$c1 = c2$$$?

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

Can someone plz give a more beginner friendly explanation to problem G. I cant understand the one given in the editorial.

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

boooooooooooooooooring round

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

what will be the time complexity of editorial of problem d? since the value of ai can go up to 1e9;

update: sorry I just forget, we are dealing with frequency. :( How can I be so dumb!

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

When Problemsetters don't want the police to bother them! Whats-App-Image-2021-03-26-at-9-30-19-AM Credits — Problem G
(For those who don't know, "AEZAKMI" is a cheat code in GTA San Andreas to escape from the police permanently)

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

I had the exact idea for D. But I didn't code it since I thought it would give TLE. Can someone explain why the solution for D won't TLE?

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

    I thought of the same thing during the contest. But the sum of n over all test cases wont exceed 2e5. So it passes.

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

    i coded it and got TLE, XD. Here in editorial they used 2 elements for priority_queue but i used only one. Though priority_queue does not work on hashing still i don't know why it gave me TLE


    //This is my code. int n; cin>>n; vector<int> a(n); unordered_map<int,int> cnt; for(int i=0;i<n;i++) cin>>a[i],cnt[a[i]]++; priority_queue<int> pq; for(auto u:cnt) pq.push(u.second); while(pq.size()>1) { int hi=pq.top(); pq.pop(); int lo=pq.top(); pq.pop(); if(hi>1) pq.push(hi-1); if(lo>1) pq.push(lo-1); } int ans=0; while(pq.size()) { ans+=pq.top(); pq.pop(); } cout<<ans<<"\n"; //This is update which gets accepted. priority_queue<vector<int>> q; //changes are here only int n; cin >> n; map<int, int> v; for (int i = 0; i < n; i++) { int x; cin >> x; v[x]++; } for (auto u: v) { q.push({u.second, u.first}); } while (q.size() >1) { auto hi = q.top(); q.pop(); auto lo = q.top(); q.pop(); hi[0]--; lo[0]--; if (hi[0]) { q.push(hi); } if (lo[0]) { q.push(lo); } } int ans = 0; while(q.size()) { ans+=q.top()[0]; q.pop(); } cout << ans << "\n";
»
5 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Weak pretests for problem E. Well, it was ultimately my mistake as I ignored the time complexity of my code

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

For question D,why can map pass this questionAccepted but use unorderd_map will TLE

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

Can anyone help me with E. Why my code got TLE? Code

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

Can someone explain the solution of G?

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

Why did my code for E gave TLE. As far as I know insert, lower_bound and upper_bound all are O(log n), so the overall complexity should be O(nlogn) right ??

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

B, C solutions with regexes instead of usual loops. Perl: B — 111112920, C — 111113262

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

Why this solution (in Python) for question E gives TLE, but this (in CPP) does not. Can anybody explain?

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

Hey does anybody knows the scoring criteria for hacking someone's solution? I made around 15 successful hacks but my rank does not seem to have improved much.

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

Can anyone show why my E problem code got RTE? https://mirror.codeforces.com/contest/1506/submission/111127527

Thanks alot

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

Can someone tell me why using unordered_map instead of map in problem D gives TLE on test case 8.

TLE when using unordered_map: https://mirror.codeforces.com/contest/1506/submission/111132652

Accepted when used map instead: https://mirror.codeforces.com/contest/1506/submission/111132742

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

can someone explain G again ?

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

    Just keeping adding the highest character to your string such that following conditions are met: (Suppose the index of your highest character is i in the orignal string(s). answer string is t)

    1. then i >index of last character in t
    2. also take lowest such i

    3.check if s[i+1....s.size()] contains all remaining characters which are not added to your answer string t.

    if any of these conditions are not met move to the next lower character. continue this process till you have added all unique characters to string t

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

I used the same approach but I got TLE on test case 3 in problem G. What is the problem? Can someone help me?

my submission : " https://mirror.codeforces.com/contest/1506/submission/111153293"

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

.

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

I did problem D with a very simple 2 pointer solution. Initialse left pointer,lft=0 & right pointer, rgt= ceil(n/2). Now,

till you the rgt is not at the end of array,
`if arr[lft]==arr[rgt]`:
      pair_count++,lft++,rgt++;`
 else
      rgt++;

final answer would be n-pair_count.

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

**** Problem E ******

I wrote O(nlogn) solution for problem E using sets but it is giving TLE in 3rd test case. Here is my solution: here.

Please anyone help me to find the problem in it. I am not able to figure it our.

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

Please can someone explain statement of problem F ? Actually, I don't really understand how it is possible to pass through all N points as the edges are directed Thanks by advance for your help!

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

[Problem E] I invented a very clean implementation of the solution to problem E.

  1. Both for max and min, maintain a pool of unused numbers;
  2. If V[i] == V[i-1], pick the most relevant element from the pool and add to solution;
  3. If V[i] != V[i-1], update the pool by all numbers in range [V[i-1] + 1, V[i] - 1], and extend both solutions by V[i].

The key point here is that the pools can be created using queue for min (we will always pick smallest non-used this way) and for max by using stack (now we will always pick the largest not used number)! This way we implement the solution in O(n) and in around 25 lines of code, max-part of it being an almost direct copy of the min-part. My solution: submission 111566779 (mal and ros are respective pools, and omal and oros are vectors for the solution to the problems).

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

Hi, don't know whats wrong with the judge of CF. I am submitting the solution for problem 'D' but then its giving wrong output on the very first test case. On other machines its running fine. Here my solution link. https://mirror.codeforces.com/contest/1506/submission/214315136

Thanks in advance if someone can help it out.

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

Hi, I dont know whats wrong with CD judge. I am submitting solution for D and its giving wrong verdict on the very first test case. On other machines its running pretty fine. Here is my solution link https://mirror.codeforces.com/contest/1506/submission/214315136

Thanks in advance if someone could help.

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

I tried solving Qn d epic transformation same way only. Reducing size one by one but got tle:https://mirror.codeforces.com/contest/1506/submission/264623957. In priority queue also we deleting one by one frequency of max element.Can anyone point out my error?