Комментарии
На chokudaiAtCoder Beginner Contest 296 Announcement, 3 года назад
0

change

if(n*n<m){
        cout<<"-1\n";
        return;
}

to

if(n < ceil_div(m, n)){
        cout<<"-1\n";
        return;
}
На chokudaiAtCoder Beginner Contest 293 Announcement, 3 года назад
0

This was the edge case, thanks!

Forgot to handle self cycle.

На chokudaiAtCoder Beginner Contest 293 Announcement, 3 года назад
0

Can't seem to get D to AC, failed 6 test cases. My idea is to label $$$2*i$$$ as blue and $$$2*i + 1$$$ as red for $$$i \in [1, n]$$$ and treat it as a graph dfs problem

Spoiler
На chokudaiAtCoder Beginner Contest 259 Announcement, 4 года назад
0

don't post your code, instead use spoiler tags

Спойлер

or just give a link to your submission

На iLoveIOIAtcoder Beginner Contest 257 Discussion?, 4 года назад
0

First find the maximum amount of digits, $$$nDigits = N / mn$$$ where $$$mn$$$ is the minimum over all $$$C_i$$$.

After that, loop from the most significant to the least significant digit while greedily assigning the digit's number by taking the maximum $$$j, j \in [1, 9]$$$, where $$$n - C_j \geq rest * mn$$$. $$$rest$$$ is the number of remaining unassigned digits. After a valid $$$j$$$ is found, reduce $$$n$$$ by $$$C_j$$$.

Submission

На mon0poleCodeJam Round 1A 2022, 4 года назад
0

Got it, so basically we need to minimize the difference between the two subsets and add to the smaller subset powers of two that add up to that difference. Thanks a bunch.

На mon0poleCodeJam Round 1A 2022, 4 года назад
0

Can you share your thought process on how you came up with the first 30 numbers being powers of two?

На ErrichtoSums and Expected Value — part 1, 4 года назад
+1

Super helpful blog!

Google Kickstart 2020 Round D — Beauty of Tree is also a cool problem that can be solved with the "contribution" technique.

На chokudaiAtCoder Beginner Contest 245 Announcement, 4 года назад
+3

I completely agree. Combined with the short statements, i always learn something new from ABC, especially D/E/F

На chokudaiAtCoder Beginner Contest 245 Announcement, 4 года назад
0

I didn't think it was impl-heavy. Notice you can determine the coefficient of $$$B_i, 0 \leq i \leq m$$$ from C[i] / A[0];

Spoiler
На FairyWinxCodeforces Round #777 (Div. 2), 4 года назад
+3

Notice you only need to do [0, 1] operation either vertically or horizontally (chessboard of size 1x2 or 2x1). Do this backwards for every row and column where there is a black cell. Edge case is when top left column is black.

На chokudaiAtCoder Beginner Contest 242 Announcement, 4 года назад
0

You can also do $$$dp[index]$$$, where $$$dp[i]$$$ denotes the number of lexicographically smaller strings for index $$$i, 1 \leq i \leq \frac{(n+1)}{2}$$$. Finally, define $$$t$$$ as follow:

    string t = s;
    for(int i=1; i<=(n+1)/2; i++)
      t[n-i] = s[i-1];

If the string $$$t$$$ is lexicographically smaller than $$$s$$$, or with c++ you can just check if $$$t \lt = s$$$, add 1 to the answer. submission

На awooEducational Codeforces Round 119 Editorial, 4 года назад
0

Here is a similar, but simpler problem to better help understand converting to other bases. C — One Quadrillion and One Dalmatians

На PhantasmagoriasCodeforces Round #745 Editorial, 4 года назад
0

It's the prefix sum of the cost, which is:

  1. cost of emptying the empty part of the portal, or the purple part of the portal if you've played Minecraft

  2. cost of adding the outer obsidian

Use long long for x, as $$$x \leq{10^{18}}$$$

I haven't implemented a BIT solution, but found one that got accepted. Hopefully, it helps. submission

На MrPaul_TUserCodeforces Round #748 (Div. 3), 5 лет назад
0

Thank you, will keep that in mind

На MrPaul_TUserCodeforces Round #748 (Div. 3), 5 лет назад
0

Edge case when $$$n \lt = 2$$$, output should be 0

На MrPaul_TUserCodeforces Round #748 (Div. 3), 5 лет назад
0

Really liked the problems!

Can anyone point out my mistake on B? Submission

I used bitmasks to simulate the removed numbers, implementation was buggy as it keeps getting WA on test 2

Neat trick! Will keep this in mind for similar problems. Thanks!

Output is the $$$id's$$$ sorted by their rankings decreasingly (bigger ranking -> more wins, or if same number of wins the smaller id gets the better rank).

What you need to do is make a custom comparator for your rankings array and sort them for every match.

I agree statement was bloated and implementation was not fun :(

Submission

Thank you, how do you know when to do heavy-light splitting? I'm having trouble identifying this type of problem

На chokudaiAtCoder Beginner Contest 217 Announcement, 5 лет назад
+3

oh what a silly mistake. Thanks!

На chokudaiAtCoder Beginner Contest 217 Announcement, 5 лет назад
0

Any idea how to solve E? I used set for the sorted items and queue for the unsorted. Implementation was full of bugs I suppose as I got 8 WA.

На chokudaiAtCoder Beginner Contest 216 Announcement, 5 лет назад
+3

Oh yeah that was an edge case. Glad I could help

На chokudaiAtCoder Beginner Contest 216 Announcement, 5 лет назад
+3

I don't know about your implementation, but I used

$$$n * ( n+1 ) / 2$$$

and reduce with n-curK using the same formula. Submission

На chokudaiAtCoder Beginner Contest 212 Announcement, 5 лет назад
0

You should use adjacency list instead of adjacency matrix for checking the banned ways, improving from $$$n^2$$$ to $$$n + 2*m$$$ for the inner loop when reducing the banned ways

На chokudaiAtCoder Beginner Contest 212 Announcement, 5 лет назад
0

D was nice, even though I couldn't pass all test cases

I'm also curious why my submission outputs empty while locally it works fine. (Josephus Problem I btw) (disclaimer: code is ugly) submission

Would be a huge help if anyone can figure out why :)

На _w_Need help in yesterday's Atcoder 162 F, 5 лет назад
0

Great explanation, helped me understand DP a bit better. Thanks.

На chokudaiAtCoder Beginner Contest 205 Announcement, 5 лет назад
0

Can anyone help explain how we get the number of banned ways here? I'm still confused while reading the editorial. Will update if I can think of a beginner friendly explanation.

Okay so I finally understood the method. Basically after computing the co-rime pairs, we loop for i in range [max(2, l), r], and for every i, we substract 2 * n_coprime - 1 from answer.

Why 2 * n_coprime - 1? Let's look at some example.

ex: [3, 7]
i = 2.
n_coprime(2) = 2, which is 4 and 6. I'll put these in a set, S = (4, 6).
To get the number of coprime pairs, we do S x S, the self product of this set which produces (4, 4) (4, 6) (6, 4) (6, 6)

let's represent this better in a n_coprime(2) by n_coprime(2) matrix, 2 x 2 matrix

(4,4) (6,4)
(4,6) (6,6)

we have a convincing pattern, the top and left borders are the g, where g = gcd(x,y) and either x/g = 1 or y/g = 1 that we need to remove.

let's see another example

ex: [3, 8]
i = 2
n_coprime = 3, S = (4, 6, 8)

co-prime pair 3x3 matrix:
(4,4) (6,4) (8,4) <
(4,6) (6,6) (8,6)
(4,8) (6,8) (8,8)
^

it looks like the pattern persists, and this is the reason of doing ans -= 2 * n_coprime(i) - 1, as 2 * n - 1 computes the number of elements in the top and left border of a matrix.

detailed explanation of example test case [3, 8]

Hope this helps, highly suggesting reading this as well if you want to understand what mobius functions does!

I walked through the example test case, which might be helpful to whoever is still confused

  gcd(x,y) = g and one of x/g != 1 or y/g != 1 is not satisfied
  is equivalent to
  gcd(x,y) = g and x = g or y = g

  ex: 3 7

  step 1:
  compute n_coprime pairs, here mu[i] denotes the mobius function of i

  i = 2, mu[2] = 1
  (4, 4) (4, 6) (6, 4) (6, 6)
  3, mu = 1
  (3, 3) (3, 6) (6, 3) (6, 6)
  4, mu = 0
  (4, 4)
  5, mu = 1
  (5, 5)
  6, mu = -1
  (6, 6)
  7, mu = 1
  (7, 7)

  ans = (4, 4) (4, 6) (6, 4) (6, 6) (3, 3) (3, 6) (6, 3) (5, 5) (7, 7)

  step 2:
  remove every g, where g = gcd(x,y) and either x/g = 1 or y/g = 1

  [i: 3]  [n_coprime(i): 2] (3, 6)  -> 2 * 2 - 1 = 3
  ans = (4, 4) (4, 6) (6, 4) (6, 6) ~(3, 3) ~(3, 6) ~(6, 3) (5, 5) (7, 7)

  [i: 4]  [n_coprime(i): 1] 4       -> 1 * 2 - 1 = 1
  ans = ~(4, 4) (4, 6) (6, 4) (6, 6) ~(3, 3) ~(3, 6) ~(6, 3) (5, 5) (7, 7)

  [i: 5]  [n_coprime(i): 1] 5       -> 1 * 2 - 1 = 1
  ans = ~(4, 4) (4, 6) (6, 4) (6, 6) ~(3, 3) ~(3, 6) ~(6, 3) ~(5, 5) (7, 7)

  [i: 6]  [n_coprime(i): 1] 6       -> 1 * 2 - 1 = 1
  ans = ~(4, 4) (4, 6) (6, 4) ~(6, 6) ~(3, 3) ~(3, 6) ~(6, 3) ~(5, 5) (7, 7)

  [i: 7]  [n_coprime(i): 1] 7       -> 1 * 2 - 1 = 1
  ans = ~(4, 4) (4, 6) (6, 4) ~(6, 6) ~(3, 3) ~(3, 6) ~(6, 3) ~(5, 5) ~(7, 7) 

  tot = 7
  9 - 7 = 2

  final ans = (4, 6) (6, 4)

i saw submissions from the leaderboard do this after computing the number of coprimes [L, R]

  for (int i = max(2, l); i <= r; i++) {
    ans -= 2 * n_coprime(i);
    ans++;
  }

I know it has something to do with removing g, where g = gcd(x,y) and either x/g = 1 or y/g = 1 but can't wrap my head around it.

example submissions: AnandOza SSRS

На chokudaiAtCoder Beginner Contest 204 Announcement, 5 лет назад
0

I think the key observation is that for every possible subset sum i inside the range [0, sum/2], there is always a corresponding subset sum sum - i. The answer is sum - i where i is the biggest i in the range [0, sum/2] where dp[i] = true. Hope this helps.

Thank you, very clean and understandable solution

Thanks, really nice problem

Sorry for the vague question, I was referring to your submission. Thank you nonetheless. Love your streams btw, hope you do more in the future.

Can you explain why we do k-- at the start? Thank you in advance!

For those who are weak in combinatorics and don't know how to solve E with it (like me), here is my submission with detailed comments. Main idea was from thescrasse's submission

See also this comment to understand more about inclusion-exclusion principle.

Hope this helps

Thank you, very detailed and understandable explanation.

Thanks, this helped a lot

На chokudaiAtCoder Beginner Contest 172 Announcement, 5 лет назад
+6

Thanks you, this is very helpful

0

Nice explanation, a bit of typo, should be $$$a[i] = (1,3),(1,4),(3,4)$$$

На okwedookCodeforces Round #703 (Div. 2) Editorial, 5 лет назад
0

Yeah, I learned to understand when to return lo and hi, rather than just memoziring it. Thanks!

Thank you for sharing, I hope this will help me get to pupil :)

На mohammedehab2002Codeforces round #717 editorial, 5 лет назад
0

Another way to think about it is the property of odd numbers which is n & 1.

If there is an odd element, then the minimum number of trailing zeros is 0, the odd number.

If there is no odd number, that means every element has a bit sequence of where there are trailing zeros.

From your example, [6 6 4 4 4] in bit form is [110 110 100 100 100], where the minimum trailing zero is 1, which is from 6.

Dividing all the elements by two is the same as removing the trailing zero (which all elements have) until there is an odd number (the least significant bit is 1)

After this operation is done, you're guaranteed to not be able to split the elements,

На mohammedehab2002Codeforces round #717 editorial, 5 лет назад
0

Awesome explanation, thanks!

На mohammedehab2002Codeforces Round #717 (Div.2), 5 лет назад
+4

partitionForces

Thank you for the detailed explanation, I finally understood E.

Really nice problems, no idea how to solve them though lol

Really interesting problems, have no idea how to solve them though lol

Thanks for the info! I've only used Atcoder Library on atcoder contests but I think I'll start using it on codeforces as well.

What does NTT stand for?

На chokudaiAtCoder Beginner Contest 192 Announcement, 5 лет назад
+5

thanks, changed from long long to __int128 and got AC

На okwedookCodeforces Round #703 (Div. 2) Editorial, 5 лет назад
0
На okwedookCodeforces Round #703 (Div. 2) Editorial, 5 лет назад
0

Ok got it, thank you for the very fast response

На okwedookCodeforces Round #703 (Div. 2) Editorial, 5 лет назад
0

In C2 solution and find_left binary search why do we return hi instead of lo?

На okwedookCodeforces Round #703 (Div. 2) Editorial, 5 лет назад
0

I see, thanks for pointing it out

На okwedookCodeforces Round #703 (Div. 2) Editorial, 5 лет назад
-14

C was a great question, I'm still confused though on my find_left function.

at first, my mid calculations were the standard (lo + hi) / 2, but this causes infinity loop:

ll mid = lo + (hi - lo) / 2;

then I changed it to (lo + hi + 1) / 2, then got AC:

ll mid = lo + (hi - lo + 1) / 2;

full code:

ll find_left(ll secondMaxIdx)
{
	ll lo = 1, hi = secondMaxIdx - 1;
	while (lo < hi)
	{
		ll mid = lo + (hi - lo) / 2;
		if (ask(mid, secondMaxIdx) == secondMaxIdx)
		{
			lo = mid;
		}
		else
		{
			hi = mid - 1;
		}
	}
	return lo;
}

Can anyone with a better understanding of binary search explain why this works?

На chokudaiAtCoder Beginner Contest 183 Announcement, 6 лет назад
0

I like how menacing your comment is because of that duck

I did nth_element(N/2) and got 1 wa. Any ideas? submission

На chokudaiAtCoder Beginner Contest 169 Announcement, 6 лет назад
-9

i cry

i cry

На vovuhРазбор Codeforces Round #636 (Div. 3), 6 лет назад
+2

same here bud, keep going

На vovuhCodeforces Round #636 (Div. 3), 6 лет назад
0

Oh wow that's such a cool way, thanks so much!

На vovuhCodeforces Round #636 (Div. 3), 6 лет назад
0

Oh wow I'm dumb. Really appreciate the explanation!

На vovuhCodeforces Round #636 (Div. 3), 6 лет назад
0

Can you explain why 2^k -1? I only know a(r^n -1)/r-1 to be the summation of geometric progression.

На MatuagkeetarpHelp in Atcoder problem., 6 лет назад
0

input = n and k. max value (we dont need to consider the 10^100 as it will be canceled out) = 1+2+...+n = n(n+1)/2

for i = k; i<=n+1; i++, you have to count the number of different values.

curmax = n(n+1)/2 — (n-i)(n-i+1)/2

// explanation: 1+2+...+n — (1+2+..+n-i) = n-i+1 + n-i+2 +...+ n-i+i

curmin = i(i+1)/2

then we increment answer with curmax-curmin + 1 (zero based)

my submission

На SulfoxCodeforces Round #635, 6 лет назад
0

i see. Thanks, your comment is very helpful. I'll keep this in mind for future competitions.

На SulfoxCodeforces Round #635, 6 лет назад
0

yeah didn't realize that. Thanks!

На SulfoxCodeforces Round #635, 6 лет назад
0

https://mirror.codeforces.com/contest/1337/submission/76887917

Can anyone help me find out why the last testcase wasn't printed? (locally it does)

Thanks!. i would like to confirm some this line on your problem C solution.

if(a[i] > b[p]){ ans += a[i] — b[p]; a[i] = b[p]; }

What I'm getting is that this is to find the blasts that doesn't instantly kill the i+1 monster so add a[i] — b[p] to ans as in the number of bullets it will take to kill after explosion. And after that we find the minimum of all a[i]..a[n] and add it to the ans as the starting point and we don't have to do anything anymore because the blasts will insta kill everything. Correct me if I'm wrong, and thanks for the video!

На PuRpLe_FoReVeRCodeforces Round #632 (Div. 2), 6 лет назад
0

bruh