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

Автор cry, 12 месяцев назад, По-английски

2148A - Sublime Sequence

Solution (written by cry)
Code (C++) (MikeMirzayanov)

2148B - Lasers

Solution (written by cry)
Code (C++) (MikeMirzayanov)

2148C - Pacer

Solution (written by cry)
Code (C++) (litfan)

2148D - Destruction of the Dandelion Fields

Solution (written by cry)
Code (C++) (AksLolCoding)

2148E - Split

Solution (written by cry)
Code (C++) (kwant)

2148F - Gravity Falls

Solution (written by cry)
Code 1 (C++) (cry)
Code 2 (Python) (Vladosiya)

2148G - Farmer John's Last Wish

Solution (written by avighankc)
Solution 2 (written by Jteh)
Code (C++) (Jteh)
Разбор задач Codeforces Round 1050 (Div. 4)
  • Проголосовать: нравится
  • +74
  • Проголосовать: не нравится

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

Fast as light

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

Fast editorial! (please like im farming)

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

I am a noob, I can't understand the rules does it mean that if I haven't participated in 5 previous rounds and solved a Question I won't get rated?

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

Problem E was a beautiful problem for a div 4.

Enjoyed the round.

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

Problem-F: How it works step by step:

Read all the lists Keep track of their lengths. Start building the final list Look at all lists that still have numbers left. From the remaining numbers in each list, pick the list whose numbers are smallest when compared from the current position. Add numbers from that list Take all remaining numbers from that list and add them to the final list. Mark that list as used so we don’t pick it again. Repeat Keep repeating until all lists are used or we have added all numbers. Print the final list This is your combined list that is as small as possible in order. Key Idea: Always pick the next list whose remaining numbers make the smallest sequence possible. Once picked, take all remaining numbers from that list. This is called a greedy approach.

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

B was easy but the problem statement was tricky to understand.

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

super fast editorial !

can any one explained me E i did not get it?

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

Got problem F accepted 10 minutes after the round got completed :( Still ENJOYED the contest :D

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

F is really a good question, a very interesting idea. Unfortunately, I couldn't come up with it during the competition (unhappy)

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

Fast editorial thanks! E and F was awwsome

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

and i was applying line equations and verifying the point of intersection, to get the total intersections for the problem B. :/

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

:(

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

F possible to solve with $$$O(\sum k)$$$ time

Oops, my solution wrong. But anyway this time complexity exist — read: https://codeforces.me/blog/entry/146112?#comment-1308911

»
12 месяцев назад, скрыть # |
Rev. 4  
Проголосовать: нравится -20 Проголосовать: не нравится

Fast editorial fr, fr.

orz to The coder, The myth, The legend, cry

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

problem C was lovely.

loads of love to the writer.

was able to solve 4 questions.

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

Is anyone else having the same messed up rankings as me? AK, penalty time 217, 10th in common standings (but not shown), 69th in friend standings

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

Wrong interpretation for a solution for F, nvm. :)

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

    Interesting idea! So clear, and also have "one pass through the data" vibe!OwO

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

    what if we don't check the unique minimum case? will it time fail directly?

    and even if we do check it suppose there are 2 identical arrays(minimums) so leading to no unique element case. In this scenario isn't this method leading to a (mx*n) time algorithm? is that fine? (could you please explain how it runs fine?)

    my similar solution also passed that didn't check for unique case but kept track of when a minimum array ends(since it gives more options) however i am not able to analyse the worst case complexity. During the contest i assumed it will exceed TL. 338529461

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

      This is true. Nice catch.

      The current implementation runs in $$$\mathcal{O}(n \cdot mx)$$$, but it can be improved to $$$\mathcal{O}\left(\sum k\right)$$$ by storing, for each column, only the indices of arrays that actually have an element there. This way every element is processed at most once.

      In the given code, however, $$$mx$$$ and $$$n$$$ are dependent — the worst case occurs when all arrays are identical (same size and same values). Even then, the bound is still manageable, since $$$\sum k = n^2$$$ which means that $$$n = \sqrt(\sum k))$$$ yeilds to $$$\mathcal{O}(\sum k * \sqrt(\sum k))$$$

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

By the way there's a typo in the editorial for E:

"There is can only be one way that all multisets can contain must the exact same elements"

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

how does the order not matter in E? like the order must matter right?

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

will i get rating as it was my third contest ?

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

Hi guys!

This was my first contest using c++, can somebody please explain to me why did my code output 33? https://codeforces.me/contest/2148/submission/338397788

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

    you call scanf with no address to store it in the loops, read into a dummy variable so that the integers are consumed

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

    Very cool bug, lol. You are getting 33 because scanf is expecting the memory address where to store the int read from the stdin. Since you have not provided any, it just ends up using the register value that was in %rdi earlier. This is undefined behavior, but here it happens to be the address of the variable n. So, all new values are read to n actually. And, since the last value in test case 2 was 32, you have n + m = 32 + 1 = 33. For test case 1, the last value and the original n value both happen to be 1 so it somehow works.

    For quick fix you can replace your scanf lines with scanf("%d", &x);. We are reading new values to x because we have no use for x and these new values. Ideally, you would declare a new int and then read in that.

    Read https://usaco.guide/general/input-output for C++ specific I/O guide.

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

    Thank you both for replying and explaining!

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

Can anyone hack my solution, don't know why it passed even though it is O(k^2logn) for F:

https://codeforces.me/contest/2148/submission/338467466

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

Can anyone tell me why my code is failing on F. https://codeforces.me/contest/2148/submission/338500676

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

For problem G, it suffices to only check prime divisors, which lowers the time complexity a lot if you precompute those.

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

oops...I failed the E implementation so hard

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

Super fast editorial... Thanks for the contest.loved problem F and happy to solve in the contest

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

I know this is not the place to ask such question, but still: is there anyway I can bypass "crawling" block, so that I will be able to continue hacking submissions?

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

    Apparently there's none; the only way to get unblocked is to just wait. From my experience, you sometimes get unblocked after a few hours, and sometimes blocking persists for more than 10 hours. So yeah, I don't know...

    I agree that it's silly to block someone who eagerly tries to hack solutions in the open hacking phase. Also the warning text is a bit too scary and unhelpful.

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

nvm

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

For some random array is the No. of times does the prefix gcd change almost O(1) ?

i.e # of times [g != __gcd(g, a[i])] this condition occurs found to be O(1) for large random array?

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

Please someone hack my f

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

too short F with python slices. i think it can be hacked

338490282

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

Problem G can be done very easily by just going through each number. Say, gcd till now is g and after adding current number, gcd becomes g', then there are only two cases —

  1. g' == g: In this case, if current element is not part of longest subarray, then answer does not change. If current element is part of longest subarray, i.e. it affects our answer, then g' has to be one of the divisors of current element. Hence ans = max(ans, F[d]), where 'd' is any divisor of current number > g as g'> g and F[] is cumulative frequency of divisors till now.

  2. g'< g: this is best case, we already found best subarray till the last element & current element decreases the gcd which satisfies the problem condition, that's what the problem is asking for!

[submission:https://codeforces.me/contest/2148/submission/338531912]

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

Problem G can be solved in $$$O(n\log n+\sum_{i=1}^{n}\tau(a_i)). $$$ My submission: 338537949

For each element, we must increment the count of each of its divisors by 1. Then, the problem boils down to finding the maximum count of a divisor such that it is not equal to the number of elements processed so far. Naively, this can be done with a multiset, but the heavy log factor TLEs. So, we can instead build a "buffer" which holds all elements with count equal to the number of elements processed so far (essentially, all elements in the buffer are divisors of the gcd so far). If the current element we process is divisible by some number x in the buffer, x remains. If not, we remove it (it does not divide the gcd anymore). The answer for the prefix is then the maximum of the count of every divisor not in the buffer.

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

Wish there was code for Solution 1 of G because my train of thought was like it. How can the maximum be maintained at O(1) per divisor? It feels like it's mandatory to check all currently counted divisors' count.

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

I don't know why, but I had a stroke reading problem E statement and understanding its meaning

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

I believe my solution for Problem F is $$$\mathcal{O}(\sum k_i)$$$. It's just about maintaining all the possible candidates for the current element. Here is The link.

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

Can someone tell me why is my code failing for F..

https://codeforces.me/contest/2148/submission/338427667

any failing testcases will be appreciated

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

can someone explain E problem , I didnt understand it

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

Can my G be hacked? ( https://codeforces.me/contest/2148/submission/338510007 )?

Uses segtrees to find most occurring prime factor, and gets TLE with segtrees of size 2e5. Realised 1e5 works a bit later and got AC with that, but still seems slightly iffy imo.

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

E is much easier than F,i think F is a good problem! btw I solve A-E so slowly because of the bad network I took half of time to load the problem and used m1.cf.com to submit lol

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

These questions are very challenging(For Div4)! My friend's F code has been hacked, haha.

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

Look at Ahmed_Nassar submissions surely they are ai solutions right? They are in the top of the leaderboard

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

Man, what the heck! My Python code for E got a TLE on test case 10 during post-contest system testing. It has the same exact logic and time complexity as the editorial's C++ solution, which feels so unfair! :((

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

Does anyone can tell me why my code is wrong on problem F? I can't figure it out.

Also, why is the indentation of the code so strange when editing, and how can I adjust the tab space?

#include <bits/stdc++.h>

#define int long long

using namespace std;

using vi = vector<int>;

int t, n;

signed main() {
	cin >> t;

	while (t -- ) {
		cin >> n;
		vector<vi> arrs(n);

		int mx = 0;
		for (int i = 0; i < n; i ++ ) {
			int k;
			cin >> k;
			mx = max(mx, k);
			vi a(k);
			for (int j = 0; j < k; j ++ ) cin >> a[j];
			arrs[i] = a;
		}
		
		sort(arrs.begin(), arrs.end(), [](const vi& a, const vi& b) {
			int mn = min(a.size(), b.size());
			for (int j = 0; j < mn; j ++ )
				if (a[j] != b[j])
					return a[j] > b[j];

			return a.size() < b.size();
		});
		
		vi res(mx);
		int pos = -1;
		for (int i = n - 1; i >= 0; --i) {
			const vi& a = arrs[i];
			int ed = a.size() - 1;
			if (pos >= ed) continue;
			for (int j = pos + 1; j <= ed; j ++ ) res[j] = a[j];
			pos = max(pos, ed);
			if (pos >= mx - 1) break;
		}

		for (auto x : res) cout << x << " " ;
		puts("");
	}

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

the test case #20 of problem F n=2 but it has only 1 following line? Am I missing something?

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

Why is my solution getting TLE? Is it solely due to the language being Python?

338599674

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

    I assume it is because of Python + using a dict instead of a vector for the counting the elements that are in ur range.

    I assume if you replace that dict, for the counting, with a list it will pass without a problem

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

how the f*ck did i fst my code is literally fkn logically equivilant to the edi like wtf ts pmo sm like ok fine i have fst i dont care, but i literally do not see a single thing wrong with my code and i am not debugging 300 lines of shit to figure ts out. i literally asked like 4 masters to check my code and i still got fst great fucking vegatables ok go downvote me now

k srry for crashout ig

anyways uh can someone tell me whats wrong lol (i seriously got no idea)

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

There is a typo in Problem F:- - Then, ki space-separated integers ai1,ai2,…,aiki follow (1≤aij≤2⋅105). it should be aik instead of aij in the bracket

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

thx for round

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

Could someone help me to understand question F?

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

F-> is anyone knows test case 19 . my code is failing on tc-19

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

Hello programmers!!!!!!!!!!!!!!!!!!!!!!!

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

Can anyone tell me why my code is giving runtime error 338645166 I am checking for out of bound in the loop but still giving error. On my compiler it is giving correct answer but cf judge is giving runtime error

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

Can Somebody explain the editorial of F(Gravity Falls),in simple language, I am having difficulty understanding that

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

    Basically, you can stack the arrays in any order and the arrays must be left-aligned (A longer array on top of a shorter one is also ok). Then, elements in each array will fall down until it touches another element (In other words, no elements are "floating"). Finally, get the elements at the bottom of the stack from left to right and form an array. Let the array be a, your task is to find the lexicographically smallest a.

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

I solved F by O(sum(k) + n)

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

My submission [338493989] was sent earlier (2025-09-13 18:35:43) and judged earlier (2025-09-14 10:27:56) than the similar submission [338456423], which was sent later (2025-09-13 19:25:16) and judged later (2025-09-14 11:23:41). I did not share my code with anyone or make it public. The similarity is coincidental, and I kindly request that this be taken into account.

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

Hey, can someone explain problem F in simple terms. I get the idea, but the implementation is difficult for me to get my head around. I also watched a yt video on problem F which had a different solution, but again, I couldn't understand a part of the implementation. I would really appreciate it if one of you guys could help me out, thank you.

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

In problem E

I’m having trouble figuring out how binary search could be applied here. Could someone please explain or share an outline of how this problem can be solved using binary search?

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

Regarding solution similarity warning

Hello, I would like to clarify the situation regarding the similarity warning for my solution to problem 2148E. During the contest, I developed the solution based on my understanding of standard algorithms and competitive programming techniques. For faster code writing and autocompletion, I used GitHub Copilot integrated in VSCode as an assistant tool to help speed up writing boilerplate code and ensure syntax correctness. At no point did I copy or refer to any solutions from other contestants or any publicly available sources. If there is any similarity with other solutions, I believe it is purely coincidental, as the problem allows for multiple correct approaches derived from well-known methods. I fully support fair play and remain committed to solving problems independently and responsibly. I kindly request the contest admins to consider my good faith efforts and not to ban my account, as I have never intentionally violated the rules. Thank you very much for your understanding and consideration.

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

wow F had beutifull sloution.

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

Hello, my solution 338490913 was flagged for coincidence with another user’s code. I do not know the other participant at all and did not share or receive any solutions anywhere (I compile my solutions offline). I solved the problem independently. The similar part of the code is generic, which I use snippets for, and the core logic seems to be analogous. Please review this case manually. Thanks!

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

I am quite confused in solution 2 of problem G, why the time complexity goes to NlogN + N(cube root (N))?? Is there any formal proof??

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

omaralimm Sorry for tagging you, i saw one of your comment say that you like the Problem G, that is why i am tagging to get some quick reply, so here is my confusion, do you have any idea??

I am quite confused in solution 2 of problem G, why the time complexity goes to NlogN + N(cube root (N))?? Is there any formal proof?? It is quite of confusing to see NlogN term and even the cube root term!

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

    I can prove it.

    Firstly, let's get all the divisors of numbers up to $$$N$$$ using sieve like method before we start solving the testcases.

    That will be $$$O(NlogN)$$$, which comes from this equation — $$$n/1 + n/2 + ... n/n = n*log(n)$$$.

    And the number of divisors of a number $$$n$$$ is $$$cbrt(n)$$$.

    So, we do precomputation with a complexity of $$$O(NlogN)$$$ and solving the testcases with a complexity of $$$O(NcbrtN)$$$.

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

Problem G can be solved with complexity $$$O(n\log A)$$$, where $$$A$$$ is the maximum element.

Let's improve the Solution 2 in the tutorial:

Suppose $$$g_k=gcd(a_1,\cdots,a_k)$$$ and $$$g_{k+1}=gcd(a_1,\cdots,a_{k+1})$$$. If $$$g_k \gt g_{k+1}$$$, then there will be a prime $$$p$$$ satisfying $$$g_{k+1}p\mid g_k$$$.

Let $$$m$$$ be the maximum integer that satisfies $$$p^m\mid g_{k+1}$$$ but $$$p^{m+1}\not\mid g_{k+1}$$$, then we have $$$p^{m+1}\mid g_k$$$. Thus, we only need to try divisors in the form of powers of prime numbers.

Since the number of divisors in this form for a number $$$x$$$ is at most $$$\log x$$$, we get the complexity at the beginning.

My submission: 339058812

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

I feel a bit confused because of the analysis for problem E:"Say our left pointer l is fixed. Until the inequality is satisfied, we will keep increasing the right pointer r. Then, we will add r−l to the answer since all subarrays a[l,l],a[l,l+1],…,a[l,r−1] are satisfied. Then, increment the left pointer by 1 and repeat." Isn't this actually a different method from the code written in the solution? In the method described in the analysis, for each l, we find the largest r such that the subarray [l, r] satisfies the condition, and then we count the subarrays from l to r. But if we implement this method directly, it would require resetting the count each time l changes, leading to O(n^2) time complexity. This method isn't the sliding window technique, right? Am I misunderstanding something or is the analysis wrong?

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

    This is two pointer and the complexity is $$$O(N)$$$,the key is come through a critical observation and also a well know method in dp which is optimization point.
    First any valid subarray must have a boarder located at somewhere between [1,n],more formally any valid [l,r],that r must in [1,n],this lead us to think if we can find when r=i,how many l satisfy then sum up we can get the answer.
    Second,optimization point in dp mean the best transition point,in different condition it may have different meaning,in this problem let opt(i-1) represent the minimum l such that it may form a valid subarray,in other word any l inside [opt(i-1),i-1] will form a valid subarray with i-1,also any l don't in that range will not form a valid subarray,and we can observe when we iterate until i,[opt(i-1),i] is including range [opt(i-1),i-1],so the opt(i) can only greater or equal than opt(i-1) otherwise since we know if opt(i)<opt(i-1) this will lead to a invalid subarray as i mention before

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

The Editorial's second solution of Problem G by Jteh can be optimized further. The $$$N\sqrt[3]{N}$$$ can be internally handled by counting the number of factors in the current iteration which have count equal to $$$i$$$. If this number is lesser than what it was in previous iteration, we simply assume our answer to be $$$i-1$$$ for prefix $$$a_1 ... a_i$$$. The Proof for this is that, the set of such numbers don't see any addition as we move forward. An element from this set is removed at some rounds, thus simply keeping the count and continuing our iteration works.

Submission: 339061514

TC: $$$O(NlogN + NlogA)$$$ where $$$A$$$ is the maximum value of $$$a_i$$$

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

2148 D

Why Wrong answer on test 2?

#include<bits/stdc++.h>
using namespace std;

int main(){
    int tc; cin>>tc;
    while(tc--){
        int n; cin>>n;
        vector<long long> val(n);
        long long total = 0;
        long long minOdd = LLONG_MAX;
        int oddCount = 0;
        for(int i=0; i<n; i++){
            cin>>val[i];
            total += val[i];
            if(val[i] % 2 != 0){
                oddCount++;
                minOdd = min(minOdd, val[i]);
            }
        }
        if(oddCount == 0)
            cout<<0<<endl;
        else if(oddCount % 2 == 1){
            cout<<total<<endl;
        }
        else{
            cout<<(total - minOdd)<<endl;
        }
    }
    return 0;
}
»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hello, I want to know that why this code for problem G (using segment tree) https://codeforces.me/contest/2148/submission/339214294

is NOT GIVING TLE

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

can someone explain why my code is wrong with string implementation, i know the solution using with int, i use string for connect the element in each array, i think i do wrong in comparing but i dont know why... i want to know my mistake but i cant find it... https://codeforces.me/contest/2148/submission/339787704

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

Problem G is very interesting

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

Is there a code implementation for solution 1 to problem G?

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

I am not getting, for, 2148E — Split, I thought i need to all possible subarray of a and need to check if this is awesome or not. But the solution code directly returning 0 if the whole subarray is not awesome. My question is why not considering other subarrays? Also I am not getting this line: "there is some way to place items outside the subarray such that all multisets contain must the exact same elements (ignoring ordering)." what do you mean by "placing items outside"? help please!!! [user:cry][user:kwant]

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

For Problem 2148E — Split: Reason behind this line in the editorial: return void(cout << 0 << endl); For a subarray [l, r] to be awesome: ∀v, in[v] x k <= cnt[v] But if some cnt[v] is not divisible by k, then we can never achieve: cnt[v] = x x k

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

the normal solution for lasers question?

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

Isn't the expected solution for second testcase for 2148D - Уничтожение полей одуванчиков wrong? Shouldn't it be 12 instead?

cry can you respond to it please.

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

how is E nlogn in editorial solution seems n^2

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

to be honest, for E author's code is too hard for beginners... this is my solution very easy to understand #383158117 or https://codeforces.me/contest/2148/submission/383158117