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

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

1800A - Is It a Cat?

Idea: Vladosiya, MikeMirzayanov

Tutorial
Solution

1800B - Count the Number of Pairs

Idea: myav

Tutorial
Solution

1800C1 - Powering the Hero (easy version)

Idea: Vladosiya

Tutorial
Solution

1800C2 - Powering the Hero (hard version)

Idea: Vladosiya

Tutorial
Solution

1800D - Remove Two Letters

Idea: MikeMirzayanov

Tutorial
Solution

1800E1 - Unforgivable Curse (easy version)

Idea: Aris, mutant

Tutorial
Solution

1800E2 - Unforgivable Curse (hard version)

Idea: Aris, Vladosiya

Tutorial
Solution

1800F - Dasha and Nightmares

Idea: Gornak40

Tutorial
Solution

1800G - Symmetree

Idea: Vladosiya

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

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

P.S. I haven't found good articles about hashing root trees so I'll post one soon.

UPD: Here it is

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

C1 was easier than A and B.

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

StringForces

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

i dont understand BFS solution of task E can anyone explain please?

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

    There is an observation that if you turn the string to a graph where the edges are like this: $$$(i,i+k)$$$ when $$$i+k \le n$$$ , $$$(i,i+k+1)$$$ when $$$i+k+1 \le n$$$. So you can swap characters in indices in the same component however you like. You can try a few examples if you want.

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

F. i guess it should be bj = bi XOR (1<<26 -1) XOR (1<<k)

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

Except C1, C2 and F, all other problems are about strings

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

So many FST's on A, such a tricky easy question !

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

So many FST's on A, such a tricky easy question !

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

What does count(all(cnt), 0) == 26 mean in solution of E2? What is the logic behind this? Can anyone tell me, please

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

    He is simply checking if count of all letters that are not in the interval [n-k; k] is equal. Count(all(cnt), 0) returns number of zero elements in the array.

    So, with this line: cnt[s[i] - 'a']++; he is counting letters in string s, and with this: cnt[t[i] - 'a']--; he is deleting letters from cnt, and when all letters were processed there will be only zeros in cnt if counts of letters were equal

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

D&G two hashing problems!

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

E can be solved using disjoint set union. Just check whether each connected component are the same.

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

Thank you for the contest, loved all the questions. Kudos to authors, coordinators. I may finally become expert after being a specialist for 6 months now, :')

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

Good tutorial. Thanks for explaining the solutions properly.

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

G is too obsivious for people who know hash of trees.

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

I thought my solution of G could fail on system test by hash-collision, but unexpectedly my solution of A got FST. There should be something like "eow" in the pretest of A.

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

Looks like this would have been my expert round had I not made a stupid error and got a penalty for overflow on problem C. Still, I won't cry about +100 delta :)

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

Can not understand why O(26⋅n⋅log n) for F got TL. Can anyone suggest what I am doing wrong? https://mirror.codeforces.com/contest/1800/submission/195673951

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

did not understand the "abudance" example in E1. Can anyone explain it to me?

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

D is a nice problem. I worried about the cases where 2 removals are not overlapping. Did it worry you too? Consider: R1+R2+S+R3+R4 where S is a string, and removals of R1+R2 and R3+R4 gives the same results: S+R3+R4 = R1+R2+S then S[even index]=R1 and S[odd index]=R2. If S has even length, R3=R1 and R4=R2; if S has odd length, R3=R2 and R4=R1. Thankfully, this shows checking overlapping removals will cover the non-overlapping ones too.

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

A,B,C1,C2,D were leaked on YT. This isn't fair. people think and try to solve and may get negative delta and others just copy and paste and get positive delta. I think Codeforses must prevent the new accounts and that solved less than N of problems in problem set to participate in Div 4 or 3

like that one : 195674461 which is for Mohamed_712 and got +44 and this answer is 100% simmilar that was leaked !

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

[deleted] Oh, my method is the same with editorial.

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

Could someone explain why we need to do "1&" and "-1&" in calc() in the solution of problem F? I thought that they wouldn't take any effect since 1 & 1 = 1 and 1 & 0 = 0, but removing them indeed resulted in WA. Here's the WA submission: 195819749

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

How to proof C? I am not convinced even the solution magically works.

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

I solved G without using hashing, but instead I "sorted" the subtrees in a certain order. Did I do a fakesolve? or is it a valid method?

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

Really good contest!

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

https://mirror.codeforces.com/contest/1800/submission/195826604, isn't the tc of this code same as the tc suggested for problem F? Why did it TLE? Can anyone help?

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

    When viewing your code, I saw two variables: ev and od. They eat a lot of time and memory, because this is a hashmap array, try to pull them apart a little and reformat the code. If it's not clear what I'm saying, then here's an idea: do not cycle(1...n) cycle (0...26) and vice versa cycle(0...26) cycle(1...n) then you can remove huge arrays and put the use of hashmap into the cycle itself, made the code faster. Sorry for grammatical errors, I do not know English.

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

Literally StringFORCES!

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

Someone pls explain this conclusion in the last paragraph of tutorial of problem F:
To count the number of pairs that include our word, we need to count the number of words with the characteristic $$$b_j=b_i\oplus(2^{26} − 1)$$$.

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

    Letter with odd count will be represented as digit 1, and that with even count will be digit 0. To find pair (i, j) which meets the condition, we should check if they miss a certain letter and all the remaining 25 letters have odd count. Note that $$$odd = odd + even$$$ is similar to $$$1 = 1 \oplus 0$$$. So the pairs we are finding are (i,j) which have $$$b_i \oplus b_j = 2^{26}-1$$$ (the right side is 26 1's). (In the implementation, we actually count words meeting $$$b_j = b_i \oplus ((2^{26}-1) \oplus 2^{c})$$$ to handle the missing letter $$$c$$$.)

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

I heard that many people did not want to understand priority_queue, so I can advise multiset. Or learn to write yourself at least a Treap).

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

Great tutorial!!!!

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

What is the meaning of this line in solution F if (brr[i] >> c & 1 ^ 1)

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
import java.util.*;
import java.io.*;

public class RemoveTwoLetters {

   public static void main(String[] args) throws IOException {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));

      int t = Integer.parseInt(br.readLine().trim());
      
      while (t-- > 0) {

         int n = Integer.parseInt(br.readLine().trim());
         String s = br.readLine();

         Set<String> set = new HashSet<>();

         for (int i = 1; i < n; i++) {
            StringBuilder sb = new StringBuilder(s.substring(0, i - 1));
            sb.append(s.substring(i + 1));
            set.add(sb.toString());
         }

         pw.print(set.size());
         pw.print('\n');
      }

      pw.flush();
      pw.close();
      br.close();
   }
}

I wrote this java solution to D, I got out of memory exception on test case 5, this could be optimized, reading insights about my solution would be fun. Please comment.

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

What does the -1 & do inside the F solution? For me it looks like no-op because -1 has 1111...111 binary representation and bitwise-and with such number shouldn't change the second number

It's just my understanding so that someone can point out what is wrong with it — I don't know much about bitwise operations

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

Can someone please tell me why my submission 195888152 with unodered_map doesn't work while the solution with map 195888396 works.

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

F is easy but I didn't solve it ontime, otherwise I would be Expert now :V

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

1800F - 31 - Dasha and Nightmares I tried solving it using bitsets in C++ but it ended up giving WA on TC3.Can anyone help me with my approach. 195952648

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

Is the argument given in the tutorial for D sufficient? i.e. what about potential over counting (the argument only considers consecutive positions)? Or is this obvious?

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

In problem 1800E2 — Unforgivable Curse (hard version) it is enough to check if index of mismatching character in string s and string t is within the limit k <= index <= n — (k + 1). accepted Code

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

Can someone explain why am I getting Wrong Answer in Problem F by using unordered_map and Accepted using map.

MAP Solution

UNORDERED MAP Solution

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

Here is my solution for problem F. Can anybody tell me where am I getting wrong? My submission link

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

So many problems based on strings

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

I dont understand for problem E when i >= k or i + k < n it doesn't guarantee the possibility of moving the letter in any direction by 1 because if i = k we aren't guaranteed to be able to move i to the right if i also equals n.

Can someone prove it to me? Thank you in advance

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

I didn't understand the editorial for problem for E like what i had observed is that if u have enough space mean if u have a length of 5 then u can replace a1,a2,a4,a5 with any character as u can right shift by 4 and then left shift by 3 and then ai and ai+1 get swapped and for the string like n=6,7,8,9 u have lot of space u can make anything .... {i get this after doing 3 4 string comparison of 6 7 length }

and when u have string <=5 then the middle element shud be equal like if u have adefc and adrfc so u can not do anything with middle element as u can not move left as well as right {u have space of 2 min is 3 } similar u can make a case for 4 -> there middle element shud be equal anf for <=3 string shud be entirely equal

if anybody can explain what they did in the editorial ???

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