atcoder_official's blog

By atcoder_official, history, 9 months ago, In English

We will hold AtCoder Beginner Contest 418.

We are looking forward to your participation!

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

»
9 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

I hope I can reach 800 in this contest.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

let's gooo

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

rp++

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Noticed that Problem C & D's scores are abnormal, also noticed that Problem E's score is just 50 points higher than D, so I think the contest will be a harder's one than before, and if I'm poor at D, I'll give it up and go to solve the E quickly.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

rp+=inf

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Please let me solve 3 problems,I am just a pupil;

»
9 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Fun fact: 418 is a joke http status code, which indicates that this server is a teapot and cannot provide coffee.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Does anyone has any idea on how to solve C?Mine's Binary Search only got 5 out of 11.Waiting for solutions.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Don't ask for solutions or help during the contest,please.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    obviously don't discuss in contest, but since contest is over now,

    • Sort the array, then make a prefix sum of it
    • For each query, find the maximum index suck that all the values are < x using the prefix sum. Let b be the number of elements less than x. Then, add (x-1)*b+1 to the previous value.
  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I solved like this I can choose any x between b to sigma Ai

    Now if b > max_element(A) then I cannot have b object of same flavor so cout<<-1<<'\n'; now case 2 If b<max_element(A) then I have to select at least n bags then as the opponent can choose all the different bags to give you to choose.

    Now even if I select n bags I have now n different flavours so I need b-1 flavour of the same type from any of the choosen n flavours . How can I gurantee that I will end having atleast b-1 flavours of same type from rest ??

    now each value of array has been decreased by 1

    5 1 4 1 8 4 9 5 sort() --? 1 4 4 8 9 look for this test case after first operation my array looks something like this 0 3 3 7 9

    now I have to make b-1 that is 4 so I have to take all the values before which is less than 4 in the new array .

    So I have to take 0 +3 + 3 = 6

    and also I have to take all the elements b-2 times which is at a index after the index of element >=b-1 and also I have to take b-1 time the same element to make it b why so because the opponent can take up to b-2 times any object as we have already used 1 of each in 1st operation so he cannot use b-1 times so he has to use b-2 times in order to maximize the x

    .

    Let the index of our use be i (the first number which is greater than equal to b-1)

    then I need in short extra of

    pref_sum[i-1]+(b-2)*(n-1-i)+(b-1) .

    so In short I need

    n+pref_sum[i-1]+(b-2)*(n-1-i)+(b-1) .where i>0 else i-1<0 so remove this

    but If I dont want to change my array I can simply do

    n+pref_sum[i-1]-i+(b-2)*(n-1-i)+(b-1).

    why so ??

    Figure it out youll understand better.

    #include <bits/stdc++.h>
    using namespace std;
    #define int long long 
    void solve() {
       int n; cin>>n; 
       int q; cin>>q; 
    	vector<int> v(n,0); 
    	for(auto &i:v) cin>>i;
    	sort(v.begin(),v.end()); 
    	vector<int> pref_sum(n,0); 
    	pref_sum[0]=v[0]; 
    	for(int i=1; i<n; i++){
    		pref_sum[i]=pref_sum[i-1]+v[i]; 
    	} 
    	while(q--){
    	int sum=0;
    	int b; cin>>b; 
    	if(b>v.back()) cout<<-1<<'\n'; 
    	else{ 
    	auto it=lower_bound(v.begin(),v.end(),b-1)-v.begin(); 
    		sum+=(n+(n-1-it)*(b-2)+(b-1)+(it>0? pref_sum[it-1]-it:0)); 
    		cout<<sum<<'\n'; 
    	}
    	}
    }
    signed  main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        solve();
    }
    
    
  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    ?I used binary search and got 100 points.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

where Will I get the solutions?

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    After the contest,there will be "editorial" button on the problem statement page.Click it to go to the editorial.

    Sometimes,in 20 minutes after the contest ends,there will be only Japanese editorials.Click the "Japanese Editorial" button to change.

»
9 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

E is a weaker version of LeetCode 3625 as the latter doesn't ensure every three points are not colinear.

»
9 months ago, hide # |
Rev. 2  
Vote: I like it +2 Vote: I do not like it

Problem E is similar to LeetCode 3625. Count Number of Trapezoids II, which appeared in the weekly contest three weeks ago.

»
9 months ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

The time limit is very bad in E.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    true i had to use unordered map

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    I used map during the contest and got AC *27,TLE *1.And I almost got mad during the contest.

    In addition,my method have to put a pair<long long,long long> and a pair<pair<long long,long long>,long long> in the unordered_map,but when I do this,I have to write the hash function by myself.It's so awful.

    The difficulty of E just worth these things above.So I dislike it very much.It makes me got -17 delta.

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I solve E with map. code

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        You're really lucky. Your maximum running time is 3990ms, which is only 10ms below the time limit.

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it +1 Vote: I do not like it

      I meet same problem at first.

      So, I used discretization + binary search to reduce the constant factors and solve it.

      I learned a lesson: don’t assume you’re just doing an ABC contest and neglect the constant factors.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    realll

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Yep, but I passed with map and fraction (a struct implemented by myself, used to do some calculations based on fractions).

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    The same

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How to solve F?

»
9 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

So close yet so far on $$$E$$$ :(

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Challenging. :)

How F and G?

»
9 months ago, hide # |
Rev. 2  
Vote: I like it +25 Vote: I do not like it

Problem G is very similar to https://qoj.ac/problem/12010. It does a great job of popularizing the Myhill–Nerode theorem. However, its downside is that it’s a bit too “brainless,” as contestants can simply copy a template they’ve written before to pass. I only spent ten minutes on it.

edit: Here is another blog about Myhill–Nerode theorem(in Chinese): https://oi-wiki.org/misc/fsm/#myhillnerode-%E5%AE%9A%E7%90%86

»
9 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

E is just Count Number of Trapezoids II, but with the tough edge cases omitted due to the easier constraints.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    My thoughts could not take me to final solution, All I observed is calculating slopes and count.

    For a given slope count ct we could make C(ct,2) lines. Then stuck at removing parallelograms.Could you guide what to do next?

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it +3 Vote: I do not like it

      There can be two approaches:

      • For a parallelogram, the mid-point of non adjacent vertices is the same, so for every pair you could store the midpoint in a map and the number of parallelograms is: (Here $$$x $$$ is the number of pairs with each midpoint) $$$ \sum{ x \choose 2}$$$.
      • We could also store the size $$$\left((x_1 - x_2)^2 + (y_1 - y_2)^2 \right)$$$, it is the property of a parallelogram to have opposite sides of same length, now for each slope, pair of segments with the same length will make a parallelogram (if they have different intercepts), so you can count them and then divide by $$$2$$$ (as we will overcount each parallelogram in the two slopes of its adjacent sides).
  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Hey uttaran can we just connect over linkedin ?https://www.linkedin.com/in/eshwarr/

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

when will the final ratings update

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

ahhhhhh only 1 min to submit my AC code of E!!!! my solution

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I am facing issue in understanding your code mainly in these steps

    sum*(sum-1) no /2 here

    we subtract (i.second)*(i.second-1)/2 (/2 here)

    at the end ans/2

    Could you explain how the extra counted parallelograms are getting subtracted.

    if we just do sum*(sum-1)/2 at each step we will have extra parallelograms that I understood.

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it +1 Vote: I do not like it

      You can simply understand this as a whole concept. mp is about the mapping of edge directions, while mpp is the mapping of lengths for edges in the same direction. For each set of edges in every direction, it is always a trapezoid. And when calculating these quantities, parallelograms will be calculated twice. So let's think differently: calculate everything twice (sum*sum-1), and for all combinations of edges with equal lengths, they are only calculated once ((i.second)*(i.second-1)/2). They will definitely be calculated again in the other direction. So in the end, all combinations of four edges containing parallel edges will be calculated twice.

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        yeah I have understood that 4*p are included at first , then we are removing 2*p (here p represent count of parallelograms). Thanks

»
9 months ago, hide # |
 
Vote: I like it +11 Vote: I do not like it

ABC are harder than CF div2 these days...

Screencast with commentary

»
9 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

lol :) lots of white iranian cheater guys ending in some suspicious numbers...

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is there an original question for this competition?(这场比赛有原题吗)

»
9 months ago, hide # |
Rev. 4  
Vote: I like it +27 Vote: I do not like it

G trash casework solution: (Good means a string which can be reduced to "1")

0000: Only good is "1"

0001: Only good is all '1's

0010: Good if "1" or starts with 10 or (starts with "11" and has at least 3 1s)

0011: Good if starts with '1'

0100: Good if "1" or ends in "01" or (ends in "11" and has at least 3 1s)

0101: Good if ends in '1'

0110: Good if odd number of '1's

0111: Good if at least one '1'

1000: Bad if "0" or "01" or "10" or "11" or "000" or "101" or "111"

1001: Good if even number of '0's

1010: Bad if "0" or "01" or "11"

1011: Bad if "0" or "01111..."

1100: Bad if "0" or "10" or "11"

1101: Bad if "0" or "...111110"

1110: Bad if "0" or "11" or "101"

1111: Only bad is "0"

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Many of the operations there are associative, and for some of them, you can obtain any number that you want if they have a small enough number of terms, you really have to do pattern matching for the remaining ones, that is, 2, 4, 11, 13.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Enumerating all theses cases during contest. (orz)

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Here is my solution for C

I solved like this I can choose any x between b to sigma Ai

Now if b > max_element(A) then I cannot have b object of same flavor so cout<<-1<<'\n'; now case 2 If b<max_element(A) then I have to select at least n bags then as the opponent can choose all the different bags to give you to choose.

Now even if I select n bags I have now n different flavours so I need b-1 flavour of the same type from any of the choosen n flavours . How can I gurantee that I will end having atleast b-1 flavours of same type from rest ??

now each value of array has been decreased by 1

5 1 4 1 8 4 9 5 sort() --? 1 4 4 8 9 look for this test case after first operation my array looks something like this 0 3 3 7 9

now I have to make b-1 that is 4 so I have to take all the values before which is less than 4 in the new array .

So I have to take 0 +3 + 3 = 6

and also I have to take all the elements b-2 times which is at a index after the index of element >=b-1 and also I have to take b-1 time the same element to make it b why so because the opponent can take up to b-2 times any object as we have already used 1 of each in 1st operation so he cannot use b-1 times so he has to use b-2 times in order to maximize the x

.

Let the index of our use be i (the first number which is greater than equal to b-1)

then I need in short extra of

pref_sum[i-1]+(b-2)*(n-1-i)+(b-1) .

so In short I need

n+pref_sum[i-1]+(b-2)*(n-1-i)+(b-1) .where i>0 else i-1<0 so remove this

but If I dont want to change my array I can simply do

n+pref_sum[i-1]-i+(b-2)*(n-1-i)+(b-1).

why so ??

Figure it out youll understand better.

#include <bits/stdc++.h>
using namespace std;
#define int long long 
void solve() {
   int n; cin>>n; 
   int q; cin>>q; 
	vector<int> v(n,0); 
	for(auto &i:v) cin>>i;
	sort(v.begin(),v.end()); 
	vector<int> pref_sum(n,0); 
	pref_sum[0]=v[0]; 
	for(int i=1; i<n; i++){
		pref_sum[i]=pref_sum[i-1]+v[i]; 
	} 
	while(q--){
	int sum=0;
	int b; cin>>b; 
	if(b>v.back()) cout<<-1<<'\n'; 
	else{ 
	auto it=lower_bound(v.begin(),v.end(),b-1)-v.begin(); 
		sum+=(n+(n-1-it)*(b-2)+(b-1)+(it>0? pref_sum[it-1]-it:0)); 
		cout<<sum<<'\n'; 
	}
	}
}
signed  main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Did anyone faced similar situations in E?

I searched "trapezoid" in baidu, a Chinese search engine, and the first result was called "不规则四边形", which means "a flat shape with four straight sides, none of which are parallel", and I couldn't understand the example or its explanation, which also didn't explain what a trapezoid was...

I only understood it after seeing its further results called "a flat shape with four straight sides, one pair of opposite sides being parallel and the other pair not parallel". What's more, the online translation websites in China also gave me the first result I mentioned, so many other participants might be puzzled.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    This is the issue of Baidu and your English.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Nowadays don't use Baidu as search engines.

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      You're right... i googled and the most of the results are correct...

      but i also found this:

      What is the definition of a trapezium? Is it a shape with exactly one pair of parallel sides or at least one pair of parallel sides? Or maybe even none at all! Different cultures define a trapezium slightly differently and many have the term trapezoid too. In the US (for some) a trapezium is a four sided polygon with no parallel sides; in the UK a trapezium is a four sided polygon with exactly one pair of parallel sides; whereas in Canada a trapezoid has an inclusive definition in that it’s a four sided-polygon with at least one pair of parallel sides — hence parallelograms are special trapezoids.

      this might explain baidu's weird results.

  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You must be knowing about 'trapezoid' from basic geometry class. If you forgot that and don't look at the wikipedia page, unfortunately, it's on you.

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      bro, English is not my first language, so you really can't expect one to remember what a "trapezoid" is while learning "梯形" in Chinese.. I also mentioned above that

      Different cultures define a trapezium slightly differently and many have the term trapezoid too

      , so I wonder why no one else faced the same problem...

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Actually, people faced the same problem. Even Um_nik mentioned it in his contest stream video.

        Apologies, I thought you have read geometry in English. This is why I always prefer to study CS or Math concepts in English. But I understand that it might create a confusion. In my country, the definition is what the question asked for.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think the E is easier than D.

»
9 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

In problem E I wanted to group edges by their slopes but I did not know how since slope take the form of x / y is there a trick for this ?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Any clue why as to this submission to E gives TLE?

submission

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Who can help me solve Problem C?I got 6 WA.I think my logic is correct. First Try Second

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How long before the English Editorial?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For question 2 considering the third given test case how can someone think they are only asking for character 't' and not for any other character?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

800+. Alhamdulliah

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How do ya'll deal with debugging when you can't see test cases? Even after the contest I couldn't figure out how (if possible at all) to view them. I'm fairly new to AtCoder so I could be missing something.

»
9 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

How to solve problem F — We're teapots ?

What i understood till now :

  • number of ways to fill coffee and tea in n length array without constraints is
    ways[0] = 1;
    ways[1] = 2; 
    for(int i = 2; i <= n; i++){
        ways[i] = (ways[i-1] + ways[i-2]) % mod2;
    }
  • number of ways to fill exactly r coffee in n length such that any two cups has atleast one tea is (n-r+1) C r
  • »
    »
    9 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    This is the toughest problem I have seen till date. Either the implementation of this is crazy tough or I am missing something.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can anyone share the soln for E, like how to make sure that u dont take the same of set of 4 pts for a trapezium again, in case of a ||gm.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

why this approach for D not works? first count all contiguous ones as they always lead to 1 so add all substring of that n*(n+1)/2 second count all contiguous zero which are even , they always lead to so add for 6 even zeros we have to add (6-1)+(6-3)+(6-5) we can make this AP series at last we have to add those transitions where one also present and then next we have even zeroes like 111000011 so this whole also results to 1 , calculation of all substring may be complex for this case ,

any other appraoch

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This is a good solution to problem D by hitoare, can anyone explain it please :

source code
»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How to do D?

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For the people asking for the solution of D:

The XNOR operation is associative, meaning the order of operations doesn't matter. For a string the final character is simply the XNOR sum of all its characters. If you notice carefully, the final sum for a string is '1' if the number of '0's is even, and '0' if the number of '0's is odd. The number of '1's doesn't affect the result.

Now, our task is to calculate the number of indexes $$$[l,r]$$$ such that count of '0's in substring $$$S_l$$$...$$$S_r$$$ is even. A substring from index $$$l$$$ to $$$r$$$ has an even number of '0's if the number of '0's in the prefix up to $$$r$$$ and the number of '0's in the prefix up to $$$l−1$$$ have the same parity.

For for each index $$$i$$$ we will check the parity of the count of '0's till now, and store that value. In the final answer we will choose how many ways we can pick $$$[l,r]$$$ from the odd and even parity respectively which is just $$$C(parityCount,2)$$$ and add them together.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Was anyone able to solve F without BST?

I can see the Japanese Tutorial mentions set or segment tree. But I don't think I completely understand the implementation given there.

»
9 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

thanks!

»
9 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

Unfortunately, I spent too much time on problem E, since at first sight, I didn't pay too much attention to the condition that [No three points are co-linear].

However, fortunately, for problem F, I have met a similar idea (almost the same) just one week ago, which is Codeforces Round 612 (Div. 2) problem F. LCC.

The idea is that, we transform the dp equation into matrix-multiplication form, and for every query, we use segment tree to handle point-updating, so that the total complexity is O(2^3 n logn).

So, you could search how to solve Codeforces Round 612 (Div. 2) problem F, and after that, I think you can surely solve today's F as well.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

When is the editorial getting published.

Hope it will be published before next contest.

»
9 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Bad time limit for E