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

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

We will hold AtCoder Beginner Contest 177.

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

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

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

Atcoder beginner at 5:30, codechef lunchtime at 7:30, tomorrow cf Div 2 666. Good happy weekends for cp lovers :>

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

I think atcoder admins are not at all interested in begineer contest now-a-days.

problems are also repeating more from some time. why?

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

How to solve problem F?

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

    Store an array $$$a$$$ where $$$a[i]$$$ denotes the minimum number of rightwards moves to get to a column $$$i$$$ at row $$$r$$$. We can simply add the fixed number of downward moves at the end. We update this at each row when we go from row $$$r$$$ to $$$r+1$$$. So in the beginning it is $$$a = {0, 0, \dots, 0}$$$. Note that when we try to move to the next row, and are forbidden from going downwards from columns $$$[L, R]$$$, we have that for $$$i\in [L, R]$$$, $$$a[i] = a[L-1] + i - (L - 1)$$$. The rest of the values in $$$a$$$ stay the same. If $$$L = 0$$$, then $$$a[i] = INF$$$ for $$$i\in [L, R]$$$, where $$$INF$$$ denotes impossibility to get to that location, formally stored as a large number. We can store the array as blocks of consecutive numbers. For example, the array $$${1, 2, 3, 2, 3, 6}$$$ could be compressed into $$${ ((0, 2), 1), ((3, 4), 2), ((5, 5), 6)}$$$, where these denote an interval and the starting number of the block of consecutive numbers. Then updates can be done in $$$\mathcal O(\log W)$$$ using a set. We then simply query for the minimum value of any block of consecutive numbers, and add the current row number for the vertical moves. If this is $$$INF$$$, then we know we can't get to this row. Overall, this runs in $$$\mathcal O(H\log W + W\log W)$$$.

    Submission

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

      Can you elaborate on the blocks of consecutive numbers and the compression of arrays?

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

        To actually do this, I use an interval union data structure (not an official name, just the name of my template). What it does is it stores a bunch of intervals (currently, it doesn't handle repeated intervals, but it's not hard to change to multiset to handle it). You can then query the intervals that intersect the a given interval in the data structure in $$$\mathcal O(X + \log I)$$$, where $$$I$$$ is the number of intervals in the structure and $$$X$$$ is the number of intervals intersected. You can also add and remove intervals in $$$\mathcal O(\log I)$$$ time. So to change a block of intervals, I simply query the intervals intersected by $$$[L, R]$$$, and remove them and update the endpoints. See my code for more details on implementation.

        If you want other problems that can use something like an interval union data structure, see Facebook Hacker Cup 2020 Round 1 problems A2 and A3, although they are a little terrible to implement.

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

How to solve F?

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

Difficulty

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

What is wrong with my solution for E?

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

How to solve D ?

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

Participated in Beginner contest for the first time. Missed the announcement, started 40 minutes late, but managed to solve 3 problems. Could you guys post the announcement 24 hours earlier, if that's not too inconvenient for you?

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

How to do C? I tried it using prefix sums and got right answers for sample inputs. Still WA.

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

.

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

For problem E can someone tell me what is wrong in my code

I got WA for 5 test cases

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

Solution of problem E(Coprime) :

Firstly we will calculate the smallest prime factor of all the numbers(due to the given constraints).

Secondly, we will store the different prime numbers in the prime factorization of a number in a set for each number in the array. We will do this for all the elements.

Lastly we will iterate over the different prime numbers of the prime factorization of all the numbers in the array, and maintain an hash array for the prime numbers found.

If we don't find any prime number which occurs in more than 1 number, then our ans will be pairwise co-prime, else, if the gcd of all numbers is 1 then the ans is setwise coprime otherwise it is not coprime

If anything is not clear, please ask.

And if anyone got a solution with better complexity, do share it.

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

Can someone tell me what is wrong with my submission for problem C?

https://atcoder.jp/contests/abc177/submissions/16372833

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

Can anyone please tell me the what is the wrong in my code. here is my solution

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

How to solve F?

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

Why are ABCs always unbalanced, how can mid-level participants use atcoder to improve?

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

Hi, someone can help me with problem E?

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

can someone explain the question F?

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

    After each of the H rows we have foreach starting position a "shift" to right if we start at that position. The starting position with the min shift is optimal to start (because it produces the shortest path).

    So we need to calculate/maintain these shifts efficiently. This is possible with a segment tree and lazy range updates, but the implementation is tricky. Because every position is not simply updated. The Update-Function is something like: newVal=max(oldVal, position-b[i])

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

if anyone is getting WA on just one test case in problem E ..try this:

3

1 1 1

answer should be "pairwise coprime"

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

Why is this approach for problem C wrong??????

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

    You have done a mistake. Consider sum1 is 1e9+8 we are at an array element 2 . Now you take addition of 2%(1e9+7) and sum1 becomes 1e9+10. Same way you have done mistakes with sum and total.

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

If anyone need short explanation & sample implementation from A-E Here

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

Can anyone explain this in problem $$$F$$$. I didn't understand this — $$$you \,cannot\, move \,down \,from \,the$$$ $$$A_i th, (A_i+1)th,...B_i th$$$ $$$squares\, from \,the \,left \,in \,the$$$ $$$i^{th}$$$ $$$row \,from \,the \,top$$$

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

from itertools import accumulate mod= 1e9+7 def main(): n = int(input()) a = list(map(int,input().split())) ans =0 ac = list(accumulate(a)) for i in range(n): ans += a[i]* (ac[-1]-ac[i]) ans %=mod print(int(ans))

Can someone tell me why answer of C is wrong in some cases when mod=1e9+7(float) but 10**9+7(int) is right. Thank you!

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

Is it true that set of distinct integers {a,b,⋯z} is pairwise coprime if its product is equal to its least common multiple? can we solve problem E using this?

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

lol during the contest on E, I was printing "set coprime" instead of "setwise coprime" and I wasn't able to debug it.

»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +45 Проголосовать: не нравится

Personal editorial for this contest:

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

For E, why if(n>80000) {cout<<"setwise coprime\n";return 0;} is not correct? In my view,$$$80,000$$$ is larger than $$$\pi(1000000)=78,498$$$ ,so there must exist $$$(i,j)$$$ which have same prime factor. my submittion

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

plz explain correct logic behind F or give a link of easy to understand submission

my WA submission

EDIT-> it is wrong because we can start from any column

WA solution

Logic-> for every row we need to find out the lowest column we can visit

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

Just a little thing here .. why have they stopped tagging this blog for each contest on the atcoder page for few time now ?

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

Hey! Can Someone help me figure out what am doing wrong here, getting WA on a few testcases.

E-Coprime

Thanks!

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

Can some tell whats wrong with my submission? Was not able to pass 2 tests:(

https://atcoder.jp/contests/abc177/submissions/16373270

The logic is to check setwise coprime, just find gcd of whole array and check if it 1. For pairwise i counted the number of numbers that are divisible by some number. If for any number, there are more than 1 numbers that are divisible by it, its not pairwise coprime.

E-Coprime

Please.

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

Can someone tell me what is wrong in my approach for E. Link

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

For problem C, we can write $$$\sum_{i =1} ^{N - 1} \sum_{j = i+ 1}^{N} A_iA_j = \frac{((\sum_{i = 1}^{N}A_i)^2 - \sum_{i = 1}^{N}A_i^2)}{2}$$$. I used this, but got WA.What is wrong with my solution?

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

In problem E I checked the condition of pair-wise coprime by using the fact that if $$$a_{1} a_{2} a_{3} ..... a_{n}$$$ are pair-wise coprime then their product = their LCM and for setwise coprime I checked that gcd over all numbers should be 1.My code is failing on some test cases.my submission

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

    lcm grows very quickly so you can't store it in even long long.

    Consider 2 primes very close to 10^6 their lcm can be as large as 10^12. So if we have n distinct primes lcm can be 10^(6*n) although that's a very light upper bound value of distinct prime also decrease but still you get the idea you can't store lcm.

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

    Your LCM will overflow, and I think your solution might not be logically correct. Let's say the lcm of the array comes out to be x and the product the array comes out to be Mod + x then in this case your solution will output pairwise coprime whereas the correct output could be any of the 3 outputs. For example let the elements of the array be [Mod, Mod, Mod, Mod] then the lcm = Mod & product = Mod ^ 4, this will lead to the answer not coprime but your solution will give pairwise coprime. This example does not fit into the constraints but there will surely be one such testcase that will fit.

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

Can someone hack my solution for problem E because I think there are weak-test cases. Here my another solution get accepted even though this fails for this simple testcase [1, 1, 6, 1].

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

Share a solution without segtree for problem F.

Code
  • »
    »
    6 лет назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится +8 Проголосовать: не нравится

    The main idea : use a set to store the nearest place in the row i which can be reached from column "j".Suppose it's d[j] for the j-th column,and use another set to store "d[j]-j" for finding the smallest "d[j]-j".

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

Either my English is poor or the statement of problem F is not clear. Please help me to understand restricted moves.

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

Can anyone please explain why I am getting TLE in problem C?

Spoiler
  • »
    »
    6 лет назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится +3 Проголосовать: не нравится

    You used 2 nested for loops, so you exceeded the time limit. Find a better approach with a better time complexity.

    It's a basic thing to notice you can't run 2 nested for loops like that. Do you know how to estimate time complexity?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
  • I'm beginner and solved A,B and C problem.I tried to use union find to solve D problem but got wrong answer.
  • I think the max size of the connected component is the answer.Is this concept wrong?What's wrong with my code?Can anyone teach me to adjust?thanks you very much. code is below (by python3)
code here...by Python3
N,M=map(int,input().split())
par=[i for i in range(N+1)]
size=[1 for i in range(N+1)]
def find(x):
    if x!=par[x]:
        par[x]=find(par[x])
    return par[x]
def union(x,y):
    if find(x)!=find(y):
        par[y] = par[x]
        size[x] += size[y]
res=N
for i in range(M):
    s,e=map(int,input().split())
    union(s,e)
print(max(size))
»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
»
4 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

in problem E

this code passed from 25 test and failed in only one test

can someone explain what's the wrong ?

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

    Corrected here.

    I debug your code in order to improve my debugging ability. You miss a case where there is no prime at all, i.e., all $$$a[i]=1$$$. So if(mx == 1) should be if(mx <= 1).

    Besides, potential integer multiplication overflow exists in your code.