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

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

We will hold AtCoder Beginner Contest 172.

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

We are looking forward to your participation!

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

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

Is there any way to view current solve-count of problems, without having to reload standings? Reloading standings take too much time with my internet connection.

It would be nice to be able to filter the ranking page by "show fav only", just like contest standing.

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

    If by reloading standings you mean using the Refresh/Auto Refresh function (in the customize option in the standing page), then I think there is no other way. (Unlike CF, the problem list page of AtCoder does not show the current solve count.)

    I hope the Auto Refresh solves your problem (as it likely updates while you are solving other problems), but it still somehow needs to download the whole standing.

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

The most interesting and hard ABC I see.

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

They made problems hard this time seeing last time many solved D and E.

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

Really liked the Problem C.

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

How to solve E?

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

I think F is quite similar to 1325D - Ehab the Xorcist. Knowing idea of this problem could be a massive help.

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

My solutions to all the problems are outlined at this link.

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

can anyone tell the logic behind how to solve C?my all sample test cases were coming out right but still it was showing WA for many

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

Can someone plz explain the solution of problem C.....??plzz

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

How to solve E and F?

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

    For E: Use the inclusion-exclusion principle. Solution

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

    for E: I solved it using inclusion-exclusion principle Submission

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

    F: From the nim-conclusion, the problem is equivalent to "given a, b, x, find k such that (a-k) xor (b+k) = x".

    Given an interval [l, r] where l is an multiple of 2^20 and r is less than l + 2^20, we can check in O(1) if there can possibly be an answer k in said interval. Once we find the interval with smallest l, we directly enumerate all values to check if there actually exists one.

    How do we check in O(1)? Notice that (a-l)>>21 and (a-r)>>21 must have a difference of at most 1, and likewise for (b+l)>>21 and (b+r)>>21. If there exists a pair (a, b), where a is one of [(a-l)>>21, (a-r)>>21] and b is one of [(b+l)>>21, (b+r)>>21], such that a^b=x>>21, then one exists.

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

      your algorithm is interesting. however, i can't understand the last part:

      if pair (aa,bb) exists and satisfies:

      1. aa belongs to [(a-l)>>21,(a-r)>>21]
      2. bb belongs to [(b+l)>>21,(b+r)>>21]
      3. aa^bb=x>>21

      then there is an answer.

      could you please explain it more in detail?

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

        Hey! I'll try my best to explain my logic here:

        Notice that for any i between l and r (l <= i <= r), then (a-i)>>21 must be either (a-l)>>21 or (a-r)>>21. Likewise, (b+i)>>21 must be either (b+l)>>21 or (b+r)>>21. Since in (a-i) xor (b+i) the first bits of (a-i) do not affect the other bits, we can regard them separately. Just taking the xor of the (almost) constant first bits, we can check if their could possibly exist an i in interval [l, r].

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

          now I can prove some of your claims to help me understand:

          (a-l)>>21 and (a-r)>>21 must have a difference of at most 1
          

          and

          any i between l and r (l <= i <= r), then (a-i)>>21 must be either (a-l)>>21 or (a-r)>>21
          

          proof:

          suppose l=x*2^k,r=(x+1)*2^k (which in your case k==20).

          (a-l)>>(k+1)
          =floor((a-l)/2^(k+1))
          =(a-l-d1)/2^(k+1) (where 0<=d1<2^(k+1))
          =(a-x*2^k-d1)/2^(k+1)
          =a/2^(k+1)-x/2-d1/x^(k+1)
          

          likewise,

          (a-r)>>(k+1)
          =floor((a-r)/2^(k+1))
          =(a-r-d2)/2^(k+1) (where 0<=d2<2^(k+1))
          =(a-(x+1)*2^k-d2)/2^(k+1)
          =a/2^(k+1)-(x+1)/2-d2/x^(k+1)
          

          hence,

          (a-l)>>(k+1)-(a-r)>>(k+1)
          =1/2+(d2-d1)/2^(k+1)
          

          because 0<=d1,d2<2^(k+1), -2^(k+1)<d2-d1<2^(k+1). thus

          (a-l)>>(k+1)-(a-r)>>(k+1)
          =1/2+(d2-d1)/2^(k+1)
          
          belongs to (1/2-1,1/2+1)=(-0.5,1.5)
          

          since (a-l)>>(k+1) and (a-r)>>(k+1) are both integer, thus (a-l)>>(k+1)-(a-r)>>(k+1) belongs to [0,1].

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

            Yep, as far as I can tell that's correct.

            Once you find an interval [l, r] that can potentially contain an answer, you just iterate through the entire interval to check.

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

          so your main strategy is:

          1. search for higher bits of a' and b'
          2. fix higher bits of a' and b'
          3. search for lower bits of a' and b'

          am i right?

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

            Yes, that is correct. This will give a total runtime of O(M sqrt(max(a))) where M is the number of higher bit matches. Although I don't know how to prove that M=O(1), it works very fast :) I'd be grateful if someone can hack my solution or prove that M is constant.

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

              I tried implementing your idea here. It passes all of the tests, except one named after_contest_01.txt. I think this test case was specially constructed to fail this solution idea.

              The input array is: $$$2^{39}-2,\ 1,\ 2^{39}-3$$$.

              There's no possible solution. But all of the intervals seem to appear as potential, thus timing out.

              PS: I know this is necroposting. But many people train using Atcoder problems and view these discussions to learn new approaches. So it might be helpful to some.

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

How to solve F?

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

https://atcoder.jp/contests/abc172/submissions/14745041

Can anyone help me why this is wrong?

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

E had a solution quite similar to Placing Rooks

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

what is wrong in my solution of problem C https://atcoder.jp/contests/abc172/submissions/14763812 getting WA on 10 test cases.

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

problem E can be solved by IEP. The closed form answer is:

$$$\left(M!+\sum_{k=1}^{N}(-1)^k\binom{N}{k}(M-k)!\right)\frac{M!}{(M-N)!^2} $$$
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

does E has something to do with derangements?

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

I am new in Atcoder. I did't see any English editorial for the problems. Is there any English tutorial available?

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

for problem E, assuming fixed A is [1,2,3...,n], ans = C(m,n) * n! * G(n, m)

which G(n, m) means given 1 ~ n for A, using 1 ~ m for B that satisfy the condition

then G(n, m) = (m — n) * G(n — 1, m — 1) + (n — 1) * ( G(n-1, m-1), G(n-2, m-2) )

G(0, m) = 1, G(1, m) = m — 1

when n == m, G(n, n) = D(n), which is derangements

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

    Can you please explain how you got that recursive relation

    or any link related to that derivation would be nice

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

      Assuming A is [1,2,3,...,n]

      When looking at what G(n, m) should be, let's imagine what the last number, x, in B should be.

      There are (m - n) ways to select x greater than n, leading us to a position where our new size is n - 1 where we still have (m - n) available numbers greater than the size (we lose the number we selected, but we gain n as a choice) This gives us the (m - n) * G(n - 1, m - 1) part of the formula

      There are (n - 1) ways to select x < n. From here, we have 2 options:

      1) select the xth number in B to n.

      This leave us with a new size to fill of n - 2, and there were still (m - n) numbers available that are not in A. This gives us the (n - 1) * G(n - 2, m - 2) part of the formula

      2) select the xth number in B to be something other than n

      Here we can imagine that x is our new 'last number', but instead of being unable to select x for it, it cannot select n for itself. Every other number works the same, so this is the same as G(n - 1,m - 1), giving us the (n - 1) * g(n - 1, m - 1) part of the formula

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

    Is there a way to solve the problem without blindly using any memorized formulas? Some form of dp? What would be a useful definition of dp[i]?

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

    During the contest, I was able to derive this formula

    G(n, m) = (m — n) * G(n — 1, m — 1) + (n — 1) * (n - m + 1) * G(n - 2, m - 1)

    I am sure this recurrence is correct but this form didn't let the computation to be in O(N)

    Thanks for sharing the formula @mickeyandkaka

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

I have a solution to the D problem with time complexity O(n).

$$$F(n) = \sum_{k=1}^n (\dfrac{k}{2} \times \left\lfloor{\dfrac{n}{k}}\right\rfloor\times \left\lfloor{1+\dfrac{n}{k}}\right\rfloor)$$$

Code (C++):

Read(&n);
for (int i = 1; i <= n; ++i) { ans += (lf(i) / 2) * (n / i) * (1 + n / i); }
printf("%.0Lf\n", ans);
»
6 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

C was way harder than D for me , i dont know if its me or the problem.

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

I used 2 pointers instead of binary search in problem C. That was easier to implement in my opinion.

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

Really liked problem E! Good contest!

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

is there any English editorial in atcoder? i am new at Atcoder

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

O(sqrt(n)) solution for D:

ll fun(ll n){
   ll x=(n*(n+1)*(2*n+1))/6;
   return x;	
}
void solve(){
    //input
   double n;
   cin>>n;
   ll i;
   ll sum=0,sum1=0;
   for(i=1;i<=sqrt(n);i++){
	   sum+=i*(i+floor(n/i))*(floor(n/i)+1-i)/2;
   }
   ll ans=2*sum-fun(sqrt(n));
   cout<<ans<<endl;
}
»
6 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится -8 Проголосовать: не нравится

Here is my solution to C.

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

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n, m, k;
	cin >> n >> m >> k;
	vector <long long> a(n), b(m);
	for (auto &i : a) cin >> i;
	for (auto &i : b) cin >> i;
	long long i=0LL, j=0LL, count = 0LL;
	while (i<n && j<m) {
		if(a[i] <= b[j]) {
			k -= a[i++];
		}
		else {
			k -= b[j++];
		}
		if (k >= 0LL)
			++count;
		else break;
	}
	bool state = true;
	while (i<n) {
		k -= a[i++];
		if (k >= 0LL)
			++count;
		else {
			state = false;
			break;
		}
	}
	if (state) {
		while (j < m) {
			k -= b[j++];
			if (k >= 0LL)
				++count;
			else break;
		}
	}
	cout << count << '\n';
}

Can anyone tell me why the above code gets WA in 10 test cases. Isn't the problem solvable by 2 pointer kinda technique?

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

    Try a case like :-

    1 2 120 101 110 10

    The correct answer should be 2 by reading the books from array B which take 110 and 10 minutes(collectively a value less than or equal to 120), but your solution gives 1(by picking 101 from array A instead).

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

      Ahh, so that means greedy will not give the optimal solution right?! Any help on how to solve the problem? The English editorial is going to take some days to come :(

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

        Since it is clear from the statement that we have to pick books exactly in the order as how they appear, the first intution can be to construct prefix sum arrays for both arrays A and B(say, arrays, prefA and prefB). Why? Because, having two prefix arrays (one for A and other for B) means that, we can find out the time to read books upto the ith book(included), in O(1) for both the arrays A and B, separately. Now, the only part remaining is to search efficiently, the maximum number of books we can read in <= K mins. We can do a binary search since, prefix arrays are always sorted. One approach could be to fix the number of books we can take from array A (0,1,2...N) one by one and if for any of these values, the time taken i.e., prefA[i] is <= K, we do a binary search on prefB to see how many books can be picked from array B, and keep updating the answer, accordingly. Hope it helps :)

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

why greedy fails for C? at each step pick up the minimum of the two.

UPD — Got it.

Testcase

UP2 — Thank you for so many testcases :)

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

Can any one tell why C fails using two pointer approach and any test case for the same.

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

This is a nice explanation of how inclusion-exclusion principle can be used to find the number of derangements. It can be extended to solve E.

Edit: Look for the proof under the formulae section.

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

i wonder why this solution WA : https://ideone.com/VIzSXP

someone helps :((

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

No English Editorial.

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

I am new to cpp, so not sure whats the problem. The code gives WA in one test case and RE in one. Rest all is accepted. Any help would be nice.

#include <bits/stdc++.h>

#define ll long long
using namespace std;

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    ll A[n]; ll B[n]; ll preA[n+1]; ll preB[m+1];
    preA[0] = 0; preB[0] = 0;
    for (ll i = 0; i < n; ++i) {
        cin >> A[i];
        preA[i+1] = preA[i] + A[i];
    }
    for (ll i = 0; i < m; ++i) {
        cin >> B[i];
        preB[i+1] = preB[i] + B[i];
    }
    ll max = 0;
    ll index = m;
    for (ll i = 0; i <= n; ++i) {
        ll totalLeft = k - preA[i];
        if (totalLeft < 0){
            break;
        }
        while (preB[index] > totalLeft){
            index--;
        }
        if (index + i > max) {
            max = index+i;
        }
    }
    cout << max;
}

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +5 Проголосовать: не нравится
C using upper bound
»
6 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Can somebody explain the solution for problem E, I am not able to understand it.

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

https://atcoder.jp/contests/abc172/submissions/14775983 can anyone help in C I used sliding window and binary search but getting wrong answers on 4 tcs .UPD-I found the bug

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится
Easy solution of D just by loop for time limit 3 sec
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hey can anyone help me out where I did wrong in problem C https://atcoder.jp/contests/abc172/submissions/14753662 Thanks in advance

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

Does anybody know why my approach to prob D gives TLE? I ran the Sieve storing, for each number, its prime factors (instead of "crossing off" the number, I stored the prime it's a multiple of.) This should be NloglogN. Then, for each number, I compute the exponent of each of it's prime factors via prime factorization (I already know all of it's prime factors, so this should be NlogN, since we can divide the number at most logN times) in order to get the number of divisors.

Note that this approach works; I don't get any WA, only some TLEs.

Does anybody have any clue?

Thanks!

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

Can someone help? Why is this code giving WA?

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

can somebody please explain me problem E with statement and how princple of inclusion exclusio works here

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

    Here is my solution with some comments about what is going on (on a best effort basis).

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

Could someone help me with problem C? I got WA in 2 test case and i don't know why here's my submission : https://atcoder.jp/contests/abc172/submissions/15825396