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

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

We will hold HHKB Programming Contest 2025(AtCoder Beginner Contest 388).

We are looking forward to your participation!

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

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

First**

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

How to turn off the sound on contest page?

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

Cake walk A-E.

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

Give a thumbs up to ABC this time! The question is very concise.

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

I think D is much harder then E.

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

Why D and E giving TLE and RE tried using difference array and BFS technique. BFS tried to optimize using DP but failed, why man ?

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

D was really educational on how to use Difference Array Dynamically with prefix sums which something i never encountered

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

Only $$$8$$$ contestants solved all the problems without any penalties. The symbol $$$\color{red}{(x)}$$$ is almost everywhere!

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

How to do E? welp

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

E is too easy for E and the difficulty gap between E and F is not reflected in the point value at all. F is a great task btw.

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

    Can you explain E?

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

      Binary search the answer. To construct x double-cakes greedily take first smallest cakes for the top part and x largest cakes for the bottom part.

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

        I tried greedy by iterating from left to right and using a multiset ,if for any index j, the smallest element in multiset satisfies the condition i just pair them up.I had the idea to binary search but then why not greedy? So can you tell me why binary search if we need to just pair them up greedily?

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

    Can you explain your approach?

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

    How did you solved F ? I figured out that if there exist a range whose size is greater than the maximum step i can take , then the answer should be No

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

      Solve it for $$$N \le 10^6$$$. Then think which cells are reachable if you have a big gap between bad segments.

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

        Can you explain how to cover the big gaps? I couldn't figure out how

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

          Handle $$$a = b$$$ separately, now assume $$$a \lt b$$$. Consider only steps $$$a$$$ and $$$a + 1$$$. With two such steps, you can reach cells $$$2a, 2a+1, 2a+2$$$. With three such steps, you can reach cells $$$3a, 3a+1, 3a+2, 3a+3$$$. Try generalizing this before reading the next paragraph.

          With $$$a$$$ such steps, you can reach cells $$$a^2, a^2 + 1, a^2 + 2, \ldots, a^2 + a$$$. With $$$a + 1$$$ such steps, you can reach cells $$$a^2 + a, a^2 + a + 1, \ldots a^2 + 2a + 1$$$. Notice how the two ranges overlap. From here on* all cells are reachable. Therefore, you can 'skip' every gap of length $$$\ge a^2 + 20$$$.

          What exactly it means to 'skip' a gap depends on how you handle small gaps. I used a BFS, so skipping means pushing $$$l-20, l-19, \ldots, l-1$$$ into the queue. Submission, LL244-249. A 'skip' may translate into code differently if you use DP.


          Alternatively, you could apply the Chicken McNugget Theorem with $$$n = a$$$, $$$m + a + 1$$$ to immediately conclude that all numbers $$$\ge a (a+1) - a - (a+1) + 1 = a^2 - a$$$ are reachable for a slightly tighter bound.

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

      My solution for problem F:

      If the transition between two reachable squares passes a bad square, then it need to have an exact number between $$$A$$$ and $$$B$$$. We will now focus on the squares within a good segment.

      For each good segment, if N is reachable, it must use one of the first B squares, same for the last B squares. So we only need to consider those squares.

      The problem now is how to transit if the segment is large. If $$$A=B$$$, then just check if the distance is a multiple of $$$A$$$. Now consider $$$A \lt B$$$, let $$$a=A,b=A+1$$$, observe $$$ax+by=c, c \gt ab-\epsilon$$$ always have a positive int solutions for $$$x,y$$$. So for steps>400 it's always possible, for the smaller range we can build a lookup table.

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

Did anybody else get WA on 2 tests in F? How did you fix it

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

    So much can go wrong in this problem, but I would first look into the case $$$a = b$$$.

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

    Happened to me. Maybe check if you're handling $$$A=B=1$$$ correctly.

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

    My approach considers values in the ranges [l-21, l-1] and [r+1, r+21] for each [li, ri], resulting in M * B values.

    If there is a bad range between two points, I will jump over it calling it short jump.

    Otherwise, I check if I can reach the point by ensuring distance-x*a <= x*(b-a)

    where x = distance/a , (LHS is dec and RHS is increasing so i would look for max value of x), I am calling this as a long jump.

    Finally, the part where you got a wa imo . You need check the current position + 2*B next position cuz eiter I would make a short jump where I would need to check pos + B or I would make a long jump where I need to check at at max B values , coming from the range at the left of me and B values , coming from the range at the right of me.

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

Liked the contest. Thanks !

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

Can anyone HELP debug this solution of F?

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

Why it is giving wrong answer

I am just finding the pair element for the element present at the beginning and remove the first element and the paired element , i am going to do this until s.is exhausted() or i can not find paired element for my current element which indicates that if there is no elemnet for me then all the lements after me is bigger than me then for them also there is no elment in the set.

// Source: https://usaco.guide/general/io

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

void solve(){
	int n;cin>>n;
//	int arr[n];
	multiset<int>s;
	for(int i=0;i<n;i++){
		int val;cin>>val;
		s.insert(val);
	}
     int ans=0;
     while(s.size()){
		
		
		// check if 2*val is there or not 
		auto it = lower_bound(s.begin(),s.end(),*s.begin()*2);

		if(it!=s.end()){
			 
			//cout<<"removing "<<*beginIt<<" and "<<*it<<'\n';
			s.erase(s.begin());
			s.erase(it);
			
			ans+=1;}

		else{
             // no 2*val is ofund
			 break;
		}

		 
	}
	cout<<ans;

}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	solve();
	// int a, b, c; cin >> a >> b >> c;
	// cout << "The sum of these three numbers is " << a + b + c << "\n";
}

Now i edited it to make it as follows:-

Traversing from the last of the set and finding the paired element for it .

If found remove last element and paired one

IF not found remove last element Do it until I have elements in the set

// Source: https://usaco.guide/general/io

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

void solve(){
	int n;cin>>n;
//	int arr[n];
	multiset<int>s;
	for(int i=0;i<n;i++){
		int val;cin>>val;
		s.insert(val);
	}
     int ans=0;
     while(s.size()){
		
		
		// check if 2*val is there or not 
		auto it =s.end();
		--it;
		int val = *it;
		auto it2 = lower_bound(s.begin(),s.end(),val/2);

		if(it2!=s.end()){
			 if(*it2==(val/2)){
				 s.erase(it);
				 s.erase(it2);
				 ans+=1;
			 }else{
				   //check if 
				   if(it2==s.begin()){
                     // all are bigger than half of it
					 s.erase(it);
				   }else{
					   --it2; // as lower bound points to at leas tgreate rthan val/2
					    s.erase(it);
				 s.erase(it2);
				 ans+=1;

				   }
			 }
		}
        else{
             // no 2*val is ofund
			 break;
		}

		 
	}
	cout<<(ans);

}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	solve();
	// int a, b, c; cin >> a >> b >> c;
	// cout << "The sum of these three numbers is " << a + b + c << "\n";
}

Any help would be grateful

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

Fkd up on D clutched on E . D was so annoying

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

I solved problem G 10 minutes after the contest ended

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

Why E and G have (basically) same statements but different constraints? I solved G first, then got RE on E because of keeping the size of arrays $$$2\times10^5$$$...

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

Problem F and G are good

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

In D first make every element give to its right and take it from left, some values will be negative now then just iterate and every negative value a tells to reduce 1 from last a elements. ex 2 9 1 2 0 4 6 7 1 5 make it -7 2 -4 -1 -1 5 9 12 8 14 then first make last 7 elements reduce by 1-> 0 2 -4 -2 -2 4 8 11 7 13 now for 2 do nothing now for -4 make last 4 elements reduce by 1 and same until last index it gives correct answer but i am not getting how to implement this in linear time, try to help

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

    let me rephrase the problem to make explanation easy
    there are $$$n$$$ person
    let person $$$i$$$ has $$$x$$$ coins
    person $$$i$$$ will give his coins from person $$$i$$$ to $$$i + a[i]$$$
    consider an array $$$b$$$
    do $$$b[i + 1] += 1$$$ and $$$b[i + x + 1] -= 1$$$
    now we can calculate $$$x$$$ (coins of person $$$i$$$) $$$ = a[i] + b[1] + b[2]..b[i]$$$
    $$$b[i] + b[2]..b[i]$$$ $$$=$$$ $$$prefb[i]$$$
    for better understanding you can search scanline technique.

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

can anyone explain in G why are we checking for the max value of j- i; such that a[j]>=2*a[i] and j>i? i came across one explanation that said that L+K−1+(max(j-i) for all i<L+mid and i>=L) <=R, but why is it so?

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

    from range $$$L..R$$$ we can choose on $$$k$$$ pairs if and only if
    for each $$$i$$$ from $$$L$$$ to $$$L + k - 1$$$
    $$$2 * a[i] \lt = a[R - (L - i)]$$$ holds, that is if we can make pairs from first $$$k$$$ elements to last $$$k$$$ elements
    let $$$j$$$ be the nearest index to $$$i$$$ such that $$$2 * a[i] \lt = a[j]$$$
    so we can choose $$$k$$$ pairs if for all $$$i$$$ in $$$L..L + k - 1$$$
    $$$j \lt = R - (L - i)$$$ holds
    $$$j - i \lt = R - L$$$
    $$$max(j - i)$$$ for all $$$i$$$ should be $$$ \lt = R - L$$$

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

How to solve G?

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

I think problem F is really a brain storm, and thank you atcoder team for providing such a nice problem!

I solved it as follows. I set E = 22, and at first have lvr = [1]. Then, for each given interval [l, r], we first check which points from [l — E, l — 1] can be reached from points belonging to lvr, and this can be done by some simple mathematical computing. We denote these points as xvr. Next, we can use BFS to check which points from [r + 1, r + E] can be reached from xvr. Then, we update lvr according to these points, and move on to the next given interval.

The key idea is that for two given intervals, we only care about some of their neighboring points, at most 22(maybe 20), and for other points, we should deal with them by mathematical computing quickly.

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

    we first check which points from [l — E, l — 1] can be reached from points belonging to lvr

    How to check this ?

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

      This can be done as follows. Assume that we have lvr=[lvr[1],lvr[2],..], (remember that lvr has at most E = 22 elements), and for each integer belonging to [l — E, l -1], denoted as y[j], we enumerate every element of lvr, and check whether there is some p, so that, lvr[i] + p * a <= y[j] and y[j] <= lvr[i] + p * b. As long as there is at least one valid value of p, then we can reach y[j].

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

Will the english editorials be released for this contest?