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

Автор Negationist, история, 5 недель назад, По-английски

In the problem: https://codeforces.me/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://codeforces.me/blog/entry/135095. Look for "vot[k][i+1]=1;." why does my way not work? Here is the code:

My Code

Полный текст и комментарии »

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

Автор Negationist, история, 6 недель назад, По-английски

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://codeforces.me/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://codeforces.me/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!

Полный текст и комментарии »

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

Автор Negationist, история, 7 недель назад, По-английски

Problem: Array Game — https://codeforces.me/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

Полный текст и комментарии »

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

Автор Negationist, история, 7 недель назад, По-английски

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://codeforces.me/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?

Полный текст и комментарии »

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

Автор Negationist, история, 7 недель назад, По-английски

Why does my rolling hash never work?

hash implementation

Полный текст и комментарии »

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

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

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.

Полный текст и комментарии »

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

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

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.

Полный текст и комментарии »

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

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

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.

Полный текст и комментарии »

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

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

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;
}

Полный текст и комментарии »

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

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

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://codeforces.me/contest/1935/submission/282863993

Полный текст и комментарии »

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

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

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://codeforces.me/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.

Полный текст и комментарии »

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