Изменения рейтингов за последние раунды временно удалены. Скоро они будут возвращены. ×
Автор awoo, история, 3 года назад, По-русски

Привет, Codeforces!

В Dec/12/2022 17:35 (Moscow time) состоится Educational Codeforces Round 139 (Rated for Div. 2).

Продолжается серия образовательных раундов в рамках инициативы Harbour.Space University! Подробности о сотрудничестве Harbour.Space University и Codeforces можно прочитать в посте.

Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.

Вам будет предложено 6 или 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.

Задачи вместе со мной придумывали и готовили Адилбек adedalic Далабаев, Владимир vovuh Петров, Иван BledDest Андросов и Максим Neon Мещеряков. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.

Удачи в раунде! Успешных решений!

UPD: Разбор опубликован

  • Проголосовать: нравится
  • +272
  • Проголосовать: не нравится

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

Best of Luck Everyone.

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

Good luck broooo❤️

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

I am looking forward to the problems of this contest, hoping to surprise me.

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

After difficult contest yesterday, I hope to change color of nickname

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

DON_F do you want to participate?

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

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

sometimes less expectations give fruitful results.

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

Currently the standings seem to be showing both Div.1 and Div.2 participants regardless of whether the "show unofficial" checkbox is checked. This isn't too much an inconvenience, but still it makes us hard to see the actual standing based on the division. Can this be fixed ASAP?

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

read-the-problem-statement-carefully forces

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

Why using Sieve for D to generate list of primes of each number up to 10^7 TLE?

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

    Send code? I got it through even with Rust:

    fn sieve(n: usize, lpf: &mut Vec<usize>, primes: &mut Vec<usize>) {
        lpf.resize(n + 1, 0);
        for x in 2..=n {
            if lpf[x] == 0 {
                lpf[x] = x;
                primes.push(x);
            }
            for i in 0..primes.len() {
                let p = primes[i];
                if x * p > n {
                    break;
                }
                lpf[x * p] = p;
                if x % p == 0 {
                    break;
                }
            }
        }
    }
    
    let lpf = &mut Vec::new();
    let primes = &mut Vec::new();
    sieve(10_000_000, lpf, primes);
    

    Should be easy to translate to C++

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

      184970170 here's mine using sieve get TLE, also probably because i use "not good" sieve

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

        I think your problem is in IO... your sieve is fast enough (should be around 2-3 seconds), but iostream is slow.

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

          sorry im new, what do you mean with iostream ? because endl?

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

            Short Answer:

            • Add ios_base::sync_with_stdio(false); to the start of your code if you want to continue using cin and cout. In that case, do not use scanf or printf.
            • Also add cin.tie(NULL); to the start of your code. Do not use endl, but print \n instead. Note that if you test your program interactively like this, then you will not see any output until termination (i.e., all of the output comes in at once at the end)

            Long Answer:

            By default, cin and cout takes some extra time to synchronize with stdout (scanf and printf), e.g. to make sure cin doesn't read something that was already read by a previous scanf. To bypass this, you can either stop using cin/cout, or you can turn off the synchronization (ios_base::sync_with_stdio(false);) and be careful not to use scanf or printf.

            The other issue is only relevant if you are printing a lot of output (shouldn't be an issue for D here). Each time you use endl or cin, the output is flushed (i.e., whatever you were supposed to display from previous cout are gonna get displayed). Each flush takes some time. We can cut down the time by only invoking one flush at program termination. This requires never using endl and to ensure that cin does not invoke a flush (achieved by setting cin.tie (NULL))

    • »
      »
      »
      3 года назад, скрыть # ^ |
      Rev. 4  
      Проголосовать: нравится 0 Проголосовать: не нравится
      ll MX = 1000*10000;
      int mx = 0;
       
      vector<vector<int>> p;
      void prep() {
          p.clear();
          p.resize(MX);
          vector<bool> pr(MX, true);
          for (int i = 2; i < MX; i++) {
              if (p[i].size()) continue;
              if (!pr[i]) continue;
              for (int j = i; j < MX; j += i) {
                  p[j].push_back(i);
                  pr[j] = false;
              }
          }
      }
      

      Your code here... ~~~~~

      ~~~~~

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

        The second for is better done like this:

        // i is prime number
        div[i] = i;
        for (long long j = (long long)i * i; j < MX; j += i) {
            div[j] = i;
            pr[j] = false;
        }
        

        Firstly, we will iterate $$$j$$$ from $$$i^2$$$. Secondly, we will save only the minimum prime divisor for each number. This algorithm works for $$$O(C log(log(C)))$$$, but written by you $$$O(Clog(C))$$$.

        Now, all divisors of a number $$$n$$$ are searched like this:

        while (n > 1) {
            // check answer for div[n]
            n /= div[n];
        }
        
  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I think generating primes till root(10^7) is sufficient for the problem.

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

    You dont need to generate prime numbers up to 10^7. Generating till sqrt(10^7) is sufficient.

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

      why?

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

        Sieve Factorization. Set a sieve of size $$$10^7$$$ where $$$sieve[i]$$$ is initialized to $$$i$$$. Then find all prime numbers up to $$$\sqrt{10^7}$$$ and use them to "mark" all composites up to $$$10^7$$$, i.e., set $$$sieve[i]$$$ to a prime factor of $$$i$$$.

        You don't need to generate the prime numbers after $$$\sqrt{10^7}$$$. We can still factorize all numbers after $$$\sqrt{10^7}$$$ this way, since all composites would be marked, and prime numbers are initially marked by themselves anyway.

        My submission: 184943623. Since we don't need the largest prime factor, we could improve this further by letting the $$$j$$$-loop start from $$$i^2$$$ instead of $$$3i$$$.

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

          So I tried a solution to generate all primes factor for all numbers up to 10^7. which should take N log log(N) ~100mil operations.

          Each number has another max 8 different prime factors, so the time to solve 10^6 cases is ~10^7. Why does this solution TLE?

          I know there's a better way to generate up only root(10^7) numbers but why does this solution TLE at 4 second ?

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

            The number of operations in a sieve is not $$$N \log \log N$$$, but rather, it is in $$$O(N \log \log N)$$$. The constant factor depends on the details of the sieve design, like whether you check even numbers or whether you generate primes beyond $$$\sqrt{N}$$$ or not. Your code seems to have none of these improvements, so the constant becomes pretty big.

            In general, a standard C++ code can comfortably perform $$$O(X)$$$ operations in 1 second when $$$X$$$ is of the order $$$10^7$$$. There are still exceptions where the constant factor is too big, but this is the general case for standard CP algorithms. However, when $$$X$$$ is of the order $$$10^8$$$, the constant factor matters immensely, and the finer details need to be sufficiently optimized to pass.

            For your approach, I expect $$$N = 10^5$$$ to run within 1 second comfortably, while $$$N = 10^6$$$ might fail 1 second but should be safe under 4 seconds, while $$$N = 10^7$$$ would definitely fail 4 seconds, and I doubt it would even pass 10 seconds, except maybe just barely. I might be wrong on these estimations, but that's what I would guess from experience. My suggestion would be to run your program to run only the sieve part (without reading any inputs or doing anything else) and check the time it takes to get a good estimation of whether it would work.

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

          Thank you, I learnt something new today — Sieve Factorization

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

      generating primes up to 10^7 is much more convenient as you can easily do that with linear sieve. Besides, given the number of test cases, traversing all the prime numbers up to sqrt(num) is a bit risky

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

    I ised linear sieve of erastothenes and it didn't led me to tle !

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

Enough of these prime number questions...

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

guys how did u fix wa16 in E??

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

Can someone please give a test case for which my code for B is failing?
https://mirror.codeforces.com/contest/1766/submission/184942949

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

In 1766D I factorized |y-x| and got TLE... is there any solution without factorization?

Update:got AC(1762ms) by using sieve and java.lang.StringBuilder(System.out.println() TLE'd)

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

please tell me there's a better solution for D aside factoring $$$|y - x|$$$. That was very painful.

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

How avoid WA16 in E?

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

Successfully solved D for the first time, E seems like a tough one, I can only think that 2 followed by a 1 with any number of 0s in between will create an extra subsequences and obviously 0s will also create extra subsequences, I tried to count that in how many sub-arrays a 0 will contribute an extra subsequence and similarly for [2...1] but didn't get the right answers, any similar ideas?

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

    My idea (didn't write up a complete solution btw, so take this with a grain of salt):

    The number of non-zero subsequences is at most 3. We can try to count how many subsegments will generate each possible number of subsequences.

    • No non-zero subsequences -> The subsegment contains only 0s. We can easily count how many there are.

    • Exactly one non-zero subsequence -> If we look at the non-zero values of the subsegment, we must not have a 2 followed by a 1 or a 1 followed by a 2 (so there is always a 3 in between)

    • Exactly two non-zero subsequences -> This seems to be the hardest, so I was planning to find this by subtracting the others off of the total.

    • Exactly three non-zero subsequences -> There are two sub-cases:

      • Second non-zero subsequence ends with 1: Subsegment contains a 2 followed by a 1 (ignoring 0s in between). Later, after some 3, we get a 1 (so both non-zero subsequences end with 1) and then a 2 (which must form a third non-zero subsequence). Ignore all 0s in between.
      • Second non-zero subsequence ends with 2: Symmetric to the other case

    The challenge I faced with these counts is on the 0s. It's not enough to just find some segment that fulfills a condition, because a group of 0s can merge easily with whatever fulfills the left side and also whatever fulfills its right side, and I couldn't figure out how to deal with this effectively.

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

Hint for D?

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

can someone pls explain how to solve e .

thanks in advance.

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

Am i the only one who wasted time by writing a stupid dp solution for C?

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

Hint for D ?

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

    Depends on how far you thought ahead.

    Hint 1
    Hint 2
    Hint 3
    Brief Overview

    My Submission: 184943623

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

      WonderFull explanation dude

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

      Can you please explain how you implemented the factorization part in your code?

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

        Are you familiar with the Sieve of Eratosthenes?

        The basic idea is that we prepare an array sieve of size $$$10^7$$$ such that the value of sieve[i] should be any prime factor of $$$i$$$. Initially, we set $$$sieve[i] = i$$$ for all $$$i$$$, with the intention of changing this later only for composite values.

        Now, for each $$$i$$$ in increasing order, check if $$$sieve[i]$$$ is still equal to $$$i$$$ (i.e., it never changed). If yes, then $$$i$$$ is prime. For each multiple of $$$i$$$, e.g., $$$ai$$$, we set $$$sieve[ai] = i$$$. Therefore, every composite number $$$i$$$ will eventually have $$$sieve[i]$$$ as one of its prime factors.

        (This can be improved in several ways. We can skip all even numbers, because it's easy to check evenness and deal with it separately without needing to utilize a sieve. When we check each $$$i$$$ in increasing order in order to find prime numbers and their multiples, we can stop when $$$i \gt \sqrt{10^7}$$$ since every composite number up to $$$10^7$$$ will have at least one prime factor $$$\leq \sqrt{10^7}$$$, so its sieve value would be set to some prime factor. Also, when finding multiples of $$$i$$$, we can start with $$$i^2$$$ since all the earlier multiples would've been covered by an earlier prime)

        After setting up the sieve, we can now factorize numbers efficiently. To factorize $$$x$$$, we read $$$sieve[x]$$$ to get one prime factor. We then divide $$$x$$$ by this factor, i.e., $$$x' = x/sieve[x]$$$. Now we can read $$$sieve[x']$$$ to get another prime factor. Repeat until $$$x$$$ is reduced to 1 in order to construct the complete prime factorization.

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

          what will happen if i generate all prime till 10e7 and linearly calculate the list of primes of y-x?

          why its giving tle ?

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

            Because it's slow. There are a lot of primes up to $$$10^7$$$. Even just generating those prime numbers will likely cause TLE, even before you try factorizing $$$y - x$$$.

            On the other hand, the efficient sieve factorization which I described that requires finding only the primes up to $$$\sqrt{10^7}$$$ is significantly faster, comfortably passing the time limit.

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

              Gotcha

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

              hi just to add on my approach is very similar to the one here, but I keep getting TLE. Does anyone know how I can optimise my code to pass D?

              My code: Code

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

                You're using a Boolean Sieve, which works great for checking if a given number is prime, but is not very efficient for actually factorizing many numbers. For each number you wish to factorize, you might have to check over 3000 prime numbers in the worst-case. With $$$10^6$$$ numbers to factorize, this would not pass the time limit.

                For Sieve Factorization, you need to make a small change to your sieve function. Instead of making the value False for a composite, make the value $$$p$$$ instead (the prime number whose multiples you're marking). There is no need to generate a list of primes. Now, to factorize a number $$$x$$$, you can read the value $$$p$$$ from the sieve list to get one factor, then divide $$$x/p$$$, read the corresponding value from the sieve list to get another factor, and so on.

                This way, the time taken to factorize a single number is proportional to the number of prime factors it decomposes into, which is at most $$$\log_2 (10^7) \lt 25$$$, much better than iterating over 3000 steps!

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

                  Hi thank you for the response! I can understand the first paragraph, but I am not sure of what you mean in the second paragraph, and how that will result in a shorter runtime. Do you happen to have any pseudocode to illustrate what you mean by "Now, to factorize a number x, you can read the value p from the sieve list to get one factor, then divide x/p, read the corresponding value from the sieve list to get another factor, and so on."?

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

                  chiralcentre Here is some simple Python code for it:

                  Preparing the Sieve
                  Factorizing an integer

                  The second block is a function that returns the list of prime factors to convey the general idea, but you can, of course, modify it accordingly to what you need.

                  You can also improve the sieve by not even allocating space for the even values, e.g., sieve[i] represents $$$2i + 1$$$, but that hurts readability, so I didn't do that here.

                  Let me know if you have any questions.

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

Problem A's harder version.

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

Solution for E:

First,calculate the contribution of 0 separately.

Next, enumerate the left endpoint $$$L=1,2,..., n $$$.

(Next we ignore 0)

We find that the answer is always no more than $$$3$$$.

$$$Ans=2$$$ : $$$a[L,R]=$$$ $$$... 1,2 ...$$$ , or $$$... 2,1 ...$$$

$$$Ans=3$$$ : $$$a[L,R]=$$$ $$$... [1,2] ... [3 ... 3 2 ... 2 1] ...$$$ , or $$$a[L,R]=$$$ $$$... [2,1] ... [3 ... 3 1 ... 1 2] ...$$$

If there is no above condition, $$$ANS=1$$$ or $$$ANS=0$$$ (all elements are $$$0$$$).

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

    I think my solution is the same. I split the array into subarrays whenever we encounter a 3, and then for each subarray, we store the occurrences of $$$[1, 2]$$$ and $$$[2, 1]$$$. Note that only the first occurrences of the subarray will contribute to the answer.

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

i think E is just case work. (correct me if i'm wrong) if you ignore all the 0, it can be proven that the maximum number subsequence will be <= 3

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

    I have a solution without any casework.

    let ignore sequence with single $$$0$$$ first since we can calculate its contribution to answer easily, then we can find that $$$3$$$ can only be at the first sequence, and there will be at most one extra sequence which only have $$$1$$$, and at most one extra sequence only have $$$2$$$.

    So we can just do $$$dp[\text{n}][\text{the last element of first sequence}][\text{flag1}][\text{flag2}]$$$ where $$$\text{flag1/flag2}$$$ represent whether we have a extra sequence with $$$1/2$$$.

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

In problem $$$B$$$, am I the only one who thought that the number of operations may be less than (n-1) ? :(

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

nice contest

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

D gave me AC with GNU 20 but TLE with 17 =(

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

Why was A, B, C like Div3 problems?

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

Hints for B ,Please ?

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

Problems were good , was a good contest

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

Speedforces :(

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

Is it possible to use Möbius inversion and binary search to solve D? Search the k and check the sum of [gcd(x+i,y+i)==1](0<=i<=k) is whether equals to (k + 1) in time limit. I spent a lot of time trying it but failed.

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

Another approach for C: Store the positions of W, in increasing order of column number. The following condition should be satisfied for the answer to exist : For any 2 consecutive position of W, if they were in the same row, then the difference between their position must be ODD, or else it should be EVEN. 184980206

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

Here are video Solutions for A-D, in case someone is interested.

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

Do we get or lose points for hacking in this round?

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

Nice E, hope to get to Master!

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

part of my code for 1766E:

//magic numbers
static int[] next1=new int[] {1,1,5,1,4,5,4,9,11,9,10,11,
			10,15,14,15};
static int[] next2=new int[] {2,4,2,2,4,5,8,5,8,10,10,11,
			14,11,14,15};
static int[] next3=new int[] {3,3,3,3,6,7,6,7,6,7,12,13,
			12,13,12,13};

wish I've come up with this idea before the contest ended

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

part of my code for 1766E

//magic numbers
	static int[] next1=new int[] {1,1,5,1,4,5,4,9,11,9,10,11,
			10,15,14,15};
	static int[] next2=new int[] {2,4,2,2,4,5,8,5,8,10,10,11,
			14,11,14,15};
	static int[] next3=new int[] {3,3,3,3,6,7,6,7,6,7,12,13,
			12,13,12,13};

wish I've come up with this idea before the contest ended

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

    Complete code ? Thank you, here's the meme for you.

    Why would you paste code without a link ? Improve your manners

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

    Explaination: In a subsequence only the last element matters. We count answer by counting 0s and non-zero sequences. For 0 at position i it contributes i*(n+1-i). We construct a FSM for another part of the anwser, where its states are represented by the last element of each non-zero sequence. By compute with brute force we can show that there are only 16 possible states: (none),1,2,3,12,21,32,31,22,11,112,221,312,321,212,121. Then we can number these states and make the state transition table manually. Remaining work is trivial.

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

can anyone tell me why my solution getting tle for problem d? https://mirror.codeforces.com/contest/1766/submission/184998801

thanks in advance.

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

Japan or2

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

We want $$$gcd(x+k, y+k) = d , (d \gt 1)$$$ then

$$$ x+k \equiv y+k \equiv 0 \mod{d} $$$

$$$ x+k \equiv y+k \mod{d} $$$

$$$ x \equiv y \mod{d} $$$

$$$ x-y \equiv 0 \mod{d} $$$

to make $$$x-y$$$ divisible by $$$d$$$, $$$d$$$ must divide $$$x-y$$$

so we will get prime factors of $$$x-y$$$

suppose that prime factors of x-y is $$$p_1, p_2, p_3,...,p_m$$$

if we return to our first equation $$$x+k \equiv y+k \equiv 0 \mod{d} $$$

substitute $$$d= p_i$$$

$$$x+k \equiv y+k \equiv 0 \mod{p_i} $$$

we have $$$x-y \equiv 0 \mod{p_i}$$$

then $$$x \equiv r \mod{p_i} \;\;\;, y \equiv r \mod{p_i} $$$

after subsititution of x and y

$$$r+k \equiv r+k \equiv 0 \mod{p_i}$$$

so k must be $$$p_i-r$$$

I get Wa on the contest because I forget to get the min for all p_i

Mysumbission

TIME (810 ms)
»
3 года назад, скрыть # |
Rev. 3  
Проголосовать: нравится -18 Проголосовать: не нравится

1766A - Extremely Round

My submission -> 185002843

Can anyone please explain why I am getting TLE on test case two of the following code?

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
    long long n,s1=0,s2=0,s3=0,s4=0;
    cin>>n;
    for(long long i=1;i<=n;i++)
    {
    if(i<10) 
        s1=i+0;
    else if(i==10||i==20||i==30||i==40||i==50||i==60||i==70||i==80||i==90||i==100) 
        s2 = i/10;
    else if(i==200||i==300||i==400||i==500||i==600||i==700||i==800||i==900||i==1000) 
        s3 =i/100-1;
    else if(i==2000||i==3000||i==4000||i==5000||i==6000||i==7000||i==8000||i==9000||i==10000) 
        s4 = i/1000-1;
    else if(i==20000||i==30000||i==40000||i==50000||i==60000||i==70000||i==80000||i==90000||i==100000) 
        s4 = i/10000-1;
    }
 
   cout<<(s1+s2+s3+s4)<<endl;
 
    }
}
»
3 года назад, скрыть # |
 
Проголосовать: нравится +47 Проголосовать: не нравится

I have a question for those who solved F (spoiler alert — it is about some part of the solution).

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

    Add edges from new_s and edges to new_t with a very negative value, and add edges from t to s with a very positive value, the new graph will not have negative cycles, find the min cost max flow in the new graph and delete new_s, new_t to run min cost flow from s to t.

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

For question D:

So I tried a solution to generate all primes factor for all numbers up to 10^7. which should take N log log(N) ~100mil operations.

Each number has another max 8 different prime factors, so the time to solve 10^6 cases is ~10^7. Why does this solution TLE?

I know there's a better way to generate up only root(10^7) numbers but why does this solution TLE at 4 second ?

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

For problem C: Hamiltonian Wall, I was getting the error. Can anyone point out where is the mistake?

t=int(input())
for _ in range(t):
    arr=[]
    x=int(input())
    y=input()
    z=input()
    arr.append(list(y))
    arr.append(list(z))
    b,w=False,False
    c=0
    flag=True
    for j in range(len(arr[0])):
        
        if arr[0][j]=='B' and arr[1][j]=='B':
            c+=-1
            
        elif arr[0][j]=='W' and arr[1][j]=='B':
            if w:
                if c%2:
                    flag=False
                    break
                else:
                    flag=True
            elif b:
                if not c%2:
                    flag=False
                    break
                else:
                    flag=True
            c=0
            w=True
        elif arr[0][j]=='B' and arr[1][j]=='W':
            if b:
                if c%2:
                    flag=False
                    break
                else:
                    flag=True
            elif w:
                if not c%2:
                    flag=False
                    break
                else:
                    flag=True
            c=0
            b=True
        else:
            flag=False
            break
    if not flag:
        print('NO')
    else:
        print('YES')
  • »
    »
    3 года назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится -21 Проголосовать: не нравится
    def solveShit():
        m = int(input())
        s = [getStrs(), getStrs()]
        cnt =0
        cur = 1
        flag = False
        for i in range(m):
            if s[0][i]==s[1][i]:
                cur = not cur
            else:
                if s[cur][i]!='B':
                    break
            cnt+=1
        if cnt==m:
            flag = True
    
        cur = 0
        cnt =0
        for i in range(m):
            if s[0][i] == s[1][i]:
                cur = not cur
            else:
                if s[cur][i] != 'B':
                    break
            cnt+=1
        if cnt==m:
            flag = True
        if flag:
            print("YES")
        else:
            print("NO")
    
»
3 года назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone explain solution of Problem E?

Thanks in Advance.

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

Can Anyone Explain Why my Solution For D Gave TLE:(

https://mirror.codeforces.com/problemset/submission/1766/184955390

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

I solved problem D offline, but no body hacked me. 184948549

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

(◕︵◕) I will be +99 at this contest but road to expert still so far.

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

My D using neal Pollard's rho code from last contest.

https://mirror.codeforces.com/contest/1766/submission/184943158

Passes under 2.5 seconds

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

Why is it rejudged twice?

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

When will the editorial be out?

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

When can l get the rattings why it shows that the contest is unrated in my constets

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

I participated in the contest. I submitted by code for problem D(184941244) and it got hacked because Time Limit exceeded. After the contest I submitted the same code(185049594) and it got accepted. I want to bring this to the notice of the authors of the contest(awoo, BledDest,Neon, adedalic) and Mike MikeMirzayanov to consider this problem and come up with a solution to this.

Thank You

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

I participated in the contest. I submitted by code for problem D(184961915) and it got hacked because of Runtime Error. After the contest I submitted the same code(185050448) and it got accepted. I want to bring this to the notice of the authors of the contest(awoo, BledDest,Neon, adedalic) and MikeMirzayanov to consider this problem and come up with a solution to this.

Thank You

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

I got TLE in 1766D - Lucky Chains after the contest because of the usage of endl instead of \n I think the solution should be considered accepted as the algorithm is fine The TLE solution 184975152 The accepted one 185056871

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

    It's unfortunate that you were unaware of the timing delays caused by endl flushes, but the reality is that the submission did not pass the time limit. There is no subjective judgment on whether a solution should be "considered" accepted or not (just like how a submission that solves 99% of the cases but fails one specific edge case is still not going to be "considered" accepted). Please instead use this as a learning experience to avoid using endl in the future. This is an important component of fast I/O, and I can see that your code already attempts to speed up the I/O.

    On that note, I would also recommend that you properly learn what your code does, instead of memorizing or preparing a template of code you don't understand. Both submissions had cin.tie (0);, but the purpose of this (prevent early flushing) is basically cancelled out by the use of endl. By the way, cout.tie (0) doesn't do anything.

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

When will the results be out??

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

Release the updates :) :), I need to see my shiny new color

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

contest ratings are not updated yet. why?

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

Where is the editorial?

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

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

Why are ratings not updated yet?

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

Where is my new slightly bigger rating???

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

Hello?It said "rated for the participants with rating lower than 2100".But the line chart in my profile shows that this Round is "unrated" for me.Is it a bug?

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

Change my color

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

So,what time does the rating change? qwq

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

How long will cyan have to wait to take over green?

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

Maybe this is the first div2F contest which everyone will be unrated lol

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

Maybe this will be the first div2 contest which everyone got unrated lol

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

When is the editorial?

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

I'm a novice. B's first idea about KMP is KMP, but I don't have any idea about KMP. I hope to give some hints

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

is it really unrated :(

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

Auto comment: topic has been updated by awoo (previous revision, new revision, compare).

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

Will we get the rating today? MikeMirzayanov, we, thousands of participants, are eagerly waiting for the rating change.

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

MikeMirzayanov, awoo. Can we knwo why the rating hasn't changed? We have waited already two days with no information. Is there a problem with the rating system or will we get our rating at all? :/

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

When will the rating get updated? Is it unrated?

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

When will the rating get updated? Is it unrated?

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

When will the rating get updated? Is it unrated?

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

why the rating has not been updated?

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

when will the ratings be out??

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

it's my first contest ㅠ_ㅠ wanna get my rating..,,

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

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

Why is the rating not updated?

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

Is it was not rated?

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

ratings vro

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

When will the rating get updated? I was going to get under zero rated for the first time :(

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

@Codeforces , atleast give update about rating changes

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

It is deadforces? No ratings updated yet

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

This has been the longest waiting time before ratings to be updated in almost 2 years.

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

I'm refreshing the page since yesterday :( ...plz release the ratings fast or atleast give an update

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

DeadForces!

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

Harshly true that awoo wants more comments to announce the rating!

source: deadforces

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

Deadforces!

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

when did rates will be updated?

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

Hey guys, it has been 3 days since the contest started. Why does it take so long :(?.

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

My rating!When can I get my rating!TAT

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

DeadForces! Where’s my rating…=_=

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

When the rating would update?

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

Cyan be waiting for too long now.

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

To everyone writing deadforces Glitches happen sometimes. Starting to make fun of such a wonderful platform is not funny. Codeforces is <3

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

i am not doing any cheating in contest ,i had give many contest at default mode of ide, till now i don't know it will be cheated at that ide. so please take my solution its my hard work on that solution i think u take it serious.

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

It would be so much easier to read the comments that discuss solutions if there were not so many people asking about the rating change. What is the problem with waiting? Obviously there is some issue and of course they must be resolving it.

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

is the rating out?? can anyone confirm?