Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

awoo's blog

By awoo, history, 3 months ago, translation, In English

1766A - Extremely Round

Idea: BledDest

Tutorial
Solution (BledDest)

1766B - Notepad#

Idea: BledDest

Tutorial
Solution (awoo)

1766C - Hamiltonian Wall

Idea: BledDest

Tutorial
Solution (awoo)

1766D - Lucky Chains

Idea: BledDest

Tutorial
Solution (adedalic)

1766E - Decomposition

Idea: BledDest

Tutorial
Solution (BledDest)

1766F - MCF

Idea: BledDest

Tutorial
Solution (BledDest)
 
 
 
 
  • Vote: I like it
  • +77
  • Vote: I do not like it

»
3 months ago, # |
  Vote: I like it +50 Vote: I do not like it

ratttttttttttttttttttttttttttttttttttttttttttttttttttttting plz

  • »
    »
    3 months ago, # ^ |
      Vote: I like it +7 Vote: I do not like it

    LOL, why so many downvotes.

  • »
    »
    3 months ago, # ^ |
      Vote: I like it +29 Vote: I do not like it

  • »
    »
    3 months ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    I had a dream, not being newbie when attending Turkish Junior National Olympics in Informatics but because of the slowest rating update ever,i can't

»
3 months ago, # |
Rev. 2   Vote: I like it +9 Vote: I do not like it

When will the ratings update? :(

»
3 months ago, # |
  Vote: I like it +34 Vote: I do not like it

It is the first time that I will have a oringe name. I really want it could update rating as quickly as possible.plz

»
3 months ago, # |
Rev. 2   Vote: I like it +28 Vote: I do not like it

I didn't read B properly and thought that $$$n$$$ could take on values other than the length of the input. I thought I needed to implement a complicated LCP+Suffix Array method than ran in $$$O(n*log(n)^2)$$$ to greedily compute the minimum number of operations needed to produce the resulting string, which I wasn't able to do during the contest.

Here's my solution which actually computes the minimum number of operations: 185016918

»
3 months ago, # |
  Vote: I like it +6 Vote: I do not like it

In A why 184918763 got TLE?

  • »
    »
    3 months ago, # ^ |
      Vote: I like it -49 Vote: I do not like it

    That's why you are grey.

  • »
    »
    3 months ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    Because you are iterating from 1 to n in each case. So the time complexity would be O(t*n) which would give TLE. You have already calculated if each i is extremely round or not. Just construct a prefix sum array which would tell how many extremely round numbers are less than i. Then you can answer each case in O(1).

  • »
    »
    3 months ago, # ^ |
    Rev. 2   Vote: I like it +15 Vote: I do not like it

    Your algorothm takes n (n = the given integer) iterations of the loop for each test case. At worst, your algorithm will have to do $$$999 \ 999$$$ iterations of the loop for each test case. A test set can contain up to $$$10^4 = 10 \ 000$$$ test cases. Your algorithm might need to do $$$10 \ 000 \cdot 999 \ 999 = 9 \ 999 \ 990 \ 000 \approx 10 \ 000 \ 000 \ 000 = 10^{10}$$$ iterations of your loop. C++ can do around $$$10^8$$$ operations on average in one second. Each iteration of your loop contains 4 fast operations: i<=n, f[i]==1, ans++ and i++. Even though these are simple and fast operations, c++ can't execute that many of them in under 3 seconds.

  • »
    »
    3 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    After finding round number you are checking every number for each queries that's why, what you can do is store round number only in array then try binary search that will reduce the time complexity.

  • »
    »
    3 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    finding law is better than exhaustion,maybe 184926907 is useful to you

  • »
    »
    3 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    184922508

    I used the log() function to do the whole problem in O(t).

»
3 months ago, # |
  Vote: I like it +4 Vote: I do not like it

For D, we can consider only prime divisors of $$$y-x$$$ because to minimize the answer, if it's possible to get $$$\gcd(x,y) \neq 1$$$ for a certain composite $$$d$$$ s.t. $$$d|(y-x)$$$, it's definitely possible for some prime $$$p < d$$$ and we can reach multiples of $$$p$$$ at least as soon as we reach a multiple of $$$d$$$.

»
3 months ago, # |
Rev. 2   Vote: I like it +76 Vote: I do not like it

state transition graph for 1766E([i] represent for a sequence end with i)

  • »
    »
    3 months ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    This state transition is sufficient enough to arrive at the intended solution.

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Nice round. I think D and E are the best problems I've ever seen.

»
3 months ago, # |
  Vote: I like it +10 Vote: I do not like it

Video Editorial of Problem C : Hamiltonian Wall Link : https://youtu.be/p4-bUeGfs48

»
3 months ago, # |
  Vote: I like it +9 Vote: I do not like it

E is simply brilliant.

»
3 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

The complexity given for B is wrong. It is O(1). There are 26^2 possible unique 2-letter strings. Any string longer than 26^2+1 will have at least one repetition due to the Pigeonhole Principle.

  • »
    »
    3 months ago, # ^ |
      Vote: I like it +34 Vote: I do not like it

    You have to read the string, so it is $$$O(n)$$$. And even if you read it character by character, in order to go to the next test case, you still have to read the whole string.

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I still don't understand why we need all the prime divisors of each number in C. Don't we only need the smallest prime divisor to know the earliest point when the chain will stop?

  • »
    »
    3 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Yeah correct, knowing the smallest is sufficient

    • »
      »
      »
      3 months ago, # ^ |
      Rev. 3   Vote: I like it +3 Vote: I do not like it

      No, take the example (4,19), y-x = 15 and the smallest prime factor is 3, however the smallest k that ensures gcd(4+k,19+k) = 3 is k = 2, but with a prime factor of 5, we find the smallest k ensuring gcd(4+k,19+k) = 5 is k = 1. That's why we run over all prime factors and take the minimum k for each.

      • »
        »
        »
        »
        3 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        actually knowing the smallest is suffice because you can iterate x /= least[x] then update the answer, which is a bit faster. My solution during contest: 184938325

        • »
          »
          »
          »
          »
          3 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Yeah I solved it that way too but I took the OP's question as "why can't you just use the smallest prime alone"

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

if anyone wants the O(1) solution for A, here it is :)

184929564

»
3 months ago, # |
  Vote: I like it +3 Vote: I do not like it

What will be the expected rating of the first 3 questions?

»
3 months ago, # |
  Vote: I like it +12 Vote: I do not like it

when will the rating be updated???

  • »
    »
    3 months ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    Perhaps the program of calculating rating change has crashed and CF stuffs are calculating manually

    • »
      »
      »
      3 months ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      what, manually???

      • »
        »
        »
        »
        3 months ago, # ^ |
          Vote: I like it +5 Vote: I do not like it

        I cannot come up with any other idea why rating has not been updated yet now

        • »
          »
          »
          »
          »
          3 months ago, # ^ |
            Vote: I like it +3 Vote: I do not like it

          manually? are you sure there are that many of them during the war?

    • »
      »
      »
      3 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      they even rolled back my rating of last to last contest for some reason D:

»
3 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Why this submission passed problem 2? Surely it's complexity is O(n^2) Your text to link here...

  • »
    »
    3 months ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    There are only 26^2 = 676 patterns of two successive characters.

    It means that this loop will end within at most approx.700*|s| times, and is enough fast to pass.

    This is called Pigeonhole principle.

    • »
      »
      »
      3 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I think any string longer than 704 will always be YES, and I guess the string below might be the longest one that can be NO.

  • »
    »
    3 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    because the test data is not large,you should notice "The sum ofnndoesn't exceed2⋅1052⋅105over all testcases."

  • »
    »
    3 months ago, # ^ |
      Vote: I like it -6 Vote: I do not like it

    Hey, one place scanf is used for taking input int len; scanf("%d",&len); In other place cin is used for taking input string s1; cin >> s1;

    is there any significance for it as in improves time or memory consumption or anything?

    Thanks.

»
3 months ago, # |
  Vote: I like it +6 Vote: I do not like it

The contest which made me master! 139 is a happy number.

  • »
    »
    3 months ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    It made me blue! (perhaps back to cyan tommorrow)

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Problem- E:- Can anyone tell, which case they where missing while they where getting WA at test case 16.

expected: '1476747', found: '996573'

How to correct it.

Thanks in advance :)

»
3 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

The B solution is wrong: Try this testcase: - t=1 - string='abcdabef' - n=6, - the answer is yes according to solution but it's wrong becuase: - 4 operations for 'abcd', - then 5th operation for copying and appending 'ab' string, - then 6th and 7th operation for 'ef', - so number of operations exceed n.

»
3 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

in problem D

why we put p-1 in [ r = min(r, ((x + p — 1) / p) * p — x); ] it should be r = min(r, ((x + r) / p) * p — x) ; why he put r = p-1 ??

»
3 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Can someone explain this block in D plz?

int r = INF;
for (int p : getPrimes(d))
	r = min(r, ((x + p - 1) / p) * p);
cout << r - x << '\n';

Why r = min(r, ((x + p - 1) / p) * p);? This means k equals (p-1)?

UPD: Ok, guess I got it. So by doing ((x + p — 1) / p) * p we get some number j, which is:

  1. p|j

  2. x <= j <= x + p — 1

  • »
    »
    3 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i didn't understand why

    • »
      »
      »
      3 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      So we need a number that is the closest to x from right side (or can be same x). Also, this number should contain some factor of number (y-x), because x+k and y-x should contain some common factor.

      How do we do it?

      By r = min(r, ((x + p - 1) / p) * p); we get some value j which is j >= x and j <= x+p-1.

      1. Why does it work? Tbh, I don't have some formal proof. Just look at examples.

      2. Why r = min(r, ((x + p - 1) / p) * p); and not r = min(r, ((x + p) / p) * p);? Look at example like this: x = 10, p = 10. Without (-1) you will get j = 20. With (-1) you will get j = 10. j = 10 is correct, because it is closer to x (x = j = 10, k = 0). OR: you could use r = min(r, ((x + p) / p) * p);, just check before it if (gcd(x, y — x) != 1). If gcd(x, y — x) != 1, then print 0 immediately.

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

My O(1) solution to problem A: 185166119

»
3 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

The Solution for Problem C is wrong. (Maybe)

For Test Case:

1

3

BWB

BWB

The output should be "NO" but it's giving "YES".

  • »
    »
    3 months ago, # ^ |
    Rev. 4   Vote: I like it 0 Vote: I do not like it

    well my approach was a dfs, and I think the code is pretty self explanatory. It works for this test case. 185170837

    I realize that should have participated when I upsolved most of the questions :cry:

  • »
    »
    3 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You are violating the requirement:

    Additionally, he wants each column to have at least one black cell, so, for each j, the following constraint is satisfied: c1,j, c2,j or both of them will be equal to 'B'.

    You have input data, which is not possible for this task. Your middle column doesn't have any black cells.

    • »
      »
      »
      3 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      oh I didn't read carefully!Thats why dfs is not needed. Thanks for clarifying that.

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

D used SPF(smallest prime factor) concept to find the prime factorisation of y-x.

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

awoo's editorial is awesome in the sense it shows us how we can approach the problem ..

»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

can anyone pls explain DP approach of problem C ?

»
3 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

A different solution for problem A

        int n;
        cin >> n;
        int sum = 0;
        while(n > 10)
        {
            sum += 9;
            n /= 10;
        }
        cout << sum + n << '\n';
»
3 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Is the concept "smallest prime factor" (minD) a well-known thing?

»
7 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Can anyone pls tell me how the value of k equal to ((x + p - 1) / p) * p in problem D ?

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

//easy solution of problem c //****can anyone tell me why a swap operation has done in if condition??

include <bits/stdc++.h>

int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr), std::cout.tie(nullptr); int T; std::cin >> T; while (T--) { int n; std::cin >> n; std::string s, t; std::cin >> s >> t; int a = 1, b = 1; for (int i = 0; i < n; ++i) { if (s[i] == 'B' && t[i] == 'B') { std::swap(a, b);////**********?? ///continue; } else { (s[i] == 'B' ? b : a) = 0; } } std::cout <<"-->"<< (a || b ? "YES" : "NO") << '\n'; } return 0; }

»
21 hour(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

the pair contribution dp thing is something i've really only seen in digit dp problems, interesting to see it works with subarrays as well :)