Negationist's blog

By Negationist, history, 10 days ago, In English

In this problem, https://mirror.codeforces.com/contest/1433/problem/F, instead of doing the holistic n^4 dp, i instead did a n^3 dp for every row, effectively(n^4 anyway), however I am wondering if this subproblem can be solved in faster than n^3? The subproblem is this, given an array of n integers, what is the maximum sum i can make of each modulo k without taking more than x items, my dp was 3d where dp[i][j][cnt] was the best answer with the first i numbers, that was congruent to to j mod k and used cnt items — so the complexity was O(n*k*x), but i cant help but wonder if there is a faster way to do it? Would that just reduce to np complete? I'm very curious.

Full text and comments »

  • Vote: I like it
  • -32
  • Vote: I do not like it

By Negationist, history, 3 weeks ago, In English

I'm sure at some point, perhaps when I hit candidate master, my ability to actually think of solutions will matter more than other things. For now however, I am seeking advice on how to be a consistent problem solver. There are two main problem I have once I get the idea. 1: implementation(efficiently), there is no shortcut I will work on it. 2: effort, if I don't like a problem, my active mind will not only barely help, but actively fight against me, on most(maybe 85%) problem's I have to look at the editorial for, usually what happens is, I look at the editorial and see something that I thought of(not just like a little piece, the whole thing), but just didn't pursue or just disregarded. Like, when I don't like the problem I do some really bad things. Today for example, I didn't do k-- before converting to binary(when I was testing the samples in my head), and so even though I had the right construction I just gave up, because I thought I had found a maximal construction(which I had) but it wasn't working. If I had even taken a second to go an code it or even think about it, I would have realized immediately what my mistake was. I feel like I never makes these kinds of mistakes when I'm at a good mental spot/like the problem(and it mostly has nothing to do with the topic, except for certain constructives which I know I don't like, in case you think its just about me solving topic that I already know). Does anyone have any advice? If I could fix this alone, even with my bad implementation, I feel like I could push 100-200 points past my peak.

Full text and comments »

  • Vote: I like it
  • +9
  • Vote: I do not like it

By Negationist, history, 3 weeks ago, In English

The problem is Adventurers(https://mirror.codeforces.com/contest/2046/problem/C). This code is cooked. Even just printing the contents of the container changes the output completely. For anyone who's up for it, what sort of magic is even going on? How do I fix it?

My Code

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

By Negationist, history, 2 months ago, In English

In the problem: https://mirror.codeforces.com/contest/2022/problem/C. My implementation involves pushing the strings one character forward to fix the off by one. In the official solution, they push the votes in a different way, here is a link: https://mirror.codeforces.com/blog/entry/135095. Look for "vot[k][i+1]=1;." why does my way not work? Here is the code:

My Code

Full text and comments »

  • Vote: I like it
  • -1
  • Vote: I do not like it

By Negationist, history, 2 months ago, In English

I feel like there are certain questions which have a specific type of implementation(maybe I am just thinking of implementation tho i feel like this may be different) where, even though you may know exactly what pattern you want to create, finding an implementation that is simple and doesn't was time with potential bugs and corner cases and such is hard. For example, I was just doing the problem: https://mirror.codeforces.com/contest/1898/problem/C.

In this problem, even though I found the conditions for a solution and the cycles in my graph that I needed, I struggled to put it together into code and went and looked at jiangly's code for it: https://mirror.codeforces.com/contest/1898/submission/233522554.

It was elegant as expected, but it made me realize am I missing this critical skill of sleek implementation that he has for annoying problems. Does any one know what I'm talking about or how to improve at this. Thanks!

Full text and comments »

  • Vote: I like it
  • +27
  • Vote: I do not like it

By Negationist, history, 3 months ago, In English

Problem: Array Game — https://mirror.codeforces.com/contest/1904/problem/C Idea of the code, consider all possible combinations of 2 elements to make diff, mn = min of, mn, diff, [first element greater than diff]-diff, [one element left of the first element greater than diff]-diff. Thanks so much.

My Code

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Negationist, history, 3 months ago, In English

Is it just me or do editorials kind of suck? Often, the methods they present are overly complicated and/or not made with idea of improving the reader's intuition in mind. It's gotten to the point that I only look for broad ideas and never look for specific implementation. And I always leave them kind of annoyed.

Example Problem: https://mirror.codeforces.com/contest/2008/problem/G (sakurako's task) What I don't like: "Now, we can find where the mexk should be in linear time. Firstly, if it is before the first one, then the answer is k, otherwise, we can assign k=k−a1. Then let's look at the second element. If a1+k<a2, then answer should be a1+k and otherwise we can assign k=k−a2+a1−1. In other words, when we look if our k can be in range from ai to ai+1, we know that number of elements that were not in the array and less than ai equal to k+ai. Then, when we find such i, we can output the answer."

This is dumb and overcomplicated. What they should have said was something like this. "Assume the array is empty, then, mex = k-1. For every array element(0 to n-1) check if mex >= i*GCD. If so, it means the mex is influenced by this array element. Thus we should do mex++. Otherwise do nothing." I went to bed trying to understand the editorial and sleeping frustrated. It seems to me like the tutorial writer care more about showing off then actually developing useful intuition.

I understand making contests and tutorials is hard but still. Some editiorials just seem so disconnected. idk. Anyone else feel this way?

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it

By Negationist, history, 3 months ago, In English

Why does my rolling hash never work?

hash implementation

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

By Negationist, history, 3 months ago, In English

I hate being the guy that spams questioning blogs but... On the problem, Did We Get Everything Covered?, I did the solution but in reverse kind of. Just look at my code and you'll see what I mean, but something is wrong. What?

Code

Edit: I failed test case 140 in test 2.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it

By Negationist, history, 3 months ago, In English

Here is an AC submission:

AC

Here is an WA submission:

WA

The only difference is a custom sqrt function. This was my worse contest ever because of this. Wasted like 40 mins trying figure this out and needed like 1 more min to solve C. Someone please explain because this is so weird and frustrating.

Full text and comments »

  • Vote: I like it
  • +4
  • Vote: I do not like it

By Negationist, history, 3 months ago, In English

In the speedbreaker question, why do we need to do: c++ mn[i]=min(mn[i],mn[i-1]),mx[i]=max(mx[i],mx[i-1]);

Full Code

Also, I get why the first condition is necessary for there to be a solutions and I get why the second part of the code finds that good interval, but I'm having a little trouble piecing together the sufficiency of the two to guarantee the right answer. Perhaps this is also why I font understand why you have to do the operations on the mins and maxes too.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Negationist, history, 3 months ago, In English

In the speedbreaker question, why do we need to do: c++ mn[i]=min(mn[i],mn[i-1]),mx[i]=max(mx[i],mx[i-1]);

I (mostly) get everything besides that. Thanks in advance!

Full submission by Zqr123456 on Div 2 contest:

Also, I get why the first condition is necessary for there to be a solutions and I get why the second part of the code finds that good interval, but I'm having a little trouble piecing together the sufficiency of the two to guarantee the right answer. Perhaps this is also why I font understand why you have to do the operations on the mins and maxes too.

#include<bits/stdc++.h>
using namespace std;
int T,n,a[200005],mn[200005],mx[200005],l,r;
void solve(){
	cin>>n;
	for(int i=0;i<=n;i++)mn[i]=n+1,mx[i]=0;
	for(int i=1;i<=n;i++)cin>>a[i],mn[a[i]]=min(mn[a[i]],i),mx[a[i]]=max(mx[a[i]],i);
	for(int i=1;i<=n;i++){
		mn[i]=min(mn[i],mn[i-1]),mx[i]=max(mx[i],mx[i-1]);
		if(mx[i]-mn[i]>=i){cout<<"0\n";return;}
	}
	l=1,r=n;
	for(int i=1;i<=n;i++)l=max(l,i-a[i]+1),r=min(r,i+a[i]-1);
	cout<<r-l+1<<'\n';
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--)solve();
	return 0;
}

Full text and comments »

  • Vote: I like it
  • +17
  • Vote: I do not like it

By Negationist, history, 3 months ago, In English

In the editorial, they use prefix sums to find the MEXs, but we can actually calculate the final MEX of the subsegments directly. This is based on the fact that if an element is in the array, there MUST be a subsegment that does NOT have it as the MEX. Thus, the final MEX(for all subsegments) must be just the MEX of the original array. With this knowledge we can simply find the first subsegment with that MEX as the MEX. From there, we look for one more subsegment with this as the MEX, if found, we are done. If not, we know it must be impossible. Please note this is my first real blog, let me know if I did something wrong.

Code: https://mirror.codeforces.com/contest/1935/submission/282863993

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Negationist, history, 3 months ago, In English

On many problems, I think of the solution very quickly but often spend a long time fixing and debugging the code to do what I want. For https://mirror.codeforces.com/problemset/problem/1973/B, I thought of a sliding window technique to find all windows that satisfy the or condition which is O(n). Yet, it took me like an hour and multiple failed submissions to get an AC. Right now, it feels like I have the "brains"(ingenuity) but not the "brawn"(implementation skills) right now. Furthermore, when I'm spending more time debugging than constructing it feels like I'm somewhat wasting my time(also its not very fun lol). What should I do?

P.S: I know someone is going to comment on how long I have been doing cp. Yes, I have only being doing cp for 1.5 months, and yes I know my implementation will naturally get better over time. Still, I'm looking for any advice BESIDES that. Thank you.

Full text and comments »

  • Vote: I like it
  • +2
  • Vote: I do not like it