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

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

We will hold AtCoder Beginner Contest 178.

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

We are looking forward to your participation!

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

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

Reminder: Contest starts in 10 mins!

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

Are there any other contest on atcoder for beginner? ABC are very good but aren't that frequeant and i tried AGC and i shouldn't have... so any other recommendation

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

deleted

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

    Inclusion Exclusion. Number of ways that we can pick any value from 0 to 9 = 10^N . Number of ways that 0 doesnt occur = number of ways to pick any value from 1 to 9 = 9^N. By same logic, number of ways that 9 doesn't occur anywhere = 9^N Number of ways that both 0 or 9 don't occur = 8^N Hence answer is 10^N — 9^N — 9^N + 8^N . Use mods wherever required

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

    Why so many downvotes he is just asking the approach didn't say anything wrong or asked anything wrong U can just use Inclusion exclusion

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

    In this question you need to find all sequences so:

    1. There is some i such that Ai = 0 (count of such i may be > 1)
    2. There is some i such that Ai = 9 (count of such i may be > 1)

    (both conditions must be met)

    Let's iterate k — number of positions i such that Ai = 0/9

    Number of ways to create "good sequences" with 0/9 is 2^k — 2 (on every position you have 2 ways to put 0/9) (-2 because you don't need to create sequences 00..000 and 99..999)

    Let's count C(n, k) — the number of ways to select a set of i positions from n positions, where we want to put 0/9

    Finally we want to fill the remaining positions with number 1..8. It is equal to 8^(n — i)

    And final number of ways for some k equal to C(n, k) * (2^k — 2) * (8^(n — i))

    P.S. more details about Binomial Coefficients you can read here Binomial Coefficients

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

Any ideas on how to do F? If the frequency of any number in first array is greater than n — (frequency of that element in the second array) than answer is "No" else answer exists.

I made a logic that the maximum frequent number in the first array will get the least frequent number from the second array. If there are multiple numbers with the same frequency then the smallest number with the smallest frequency goes to the largest number with the largest frequency. I was not quite able to implement it.

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

Solved E but coudnt solve C and D :(.

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

How to do D?

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

How to solve E? I tried to find smallest and largest points on x and y axis(total 8 points) and found maximum among them.

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

Pure Mathematics Contest!!

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

Maybe E is just a too well known problem, but F solution was more obvious to me than E solution.

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

MathCoder literally :V

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

What are the solutions for problems E and F?

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

Hi, this is my code for F problem

I am failing in 3 test cases and I couldn't figure out those TCs,

you can find my code in this link please help me

https://ideone.com/7PaZ9k

My submission link https://atcoder.jp/contests/abc178/submissions/16710181

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

F solution: Reverse array B, then A will be in ascending order and B will be in descending order. If we now look at positions where A[i] == B[i], they will form a segment [l, r], and will all have equal element A[i] == B[i] == C. Then you just need to swap all positions i from this segment with such positions j that A[j] != C and B[j] != C. And if there are not enough such positions j then I think it's not hard to prove that reordering is not possible at all.

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

Man problem C ruined the round for me!:) Can anyone please explain the approach for it?

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

what's wrong in my solution of F? getting wrong answers on 6/50 test cases?

https://atcoder.jp/contests/abc178/submissions/16721049

UPD: I did some changes in my above code but still it's giving wrong answer on 3 test-cases :( https://atcoder.jp/contests/abc178/submissions/16724818

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

Anyways to do C or D without DP ?

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

    C is simple inclusion — exclusion. My one line code :

    cout << sub(add(power(10, n), power(8, n)), add(power(9, n), power(9, n)));

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

    D could be solve by brute force the number of elements in the sequence and the do a star-and-bar-like counting trick.

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится
    My approach of D (Without dp ) :
    First of all fix the length of the sequence .
    Suppose length is 5 ;
    so a1 + a2 + a3 + a4 + a5 = S ; now for all i , a[i]>=3 ;
    using stars and bars technique  ,
    no of solution  of that equation is ncr(s-3*length +length -1 , length-1);here length = 5 ;
    final answer = sum of solutions for each fixed length .
    
    Code
  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    I did D using combinatorics. It is the modified version of distributing n balls into r urns such that each urn contains at least 1 ball.

    Solution of standard problem: (n-1)C(r-1).

    Here problem can be reformulated as if you can use any number of urns (because the length of sequence can vary) and each urn should contain at least 3 balls.

    Solution: summation of (n-1-2*i)C(i-1) for all i, where i is the number of urns and n is the sum we want. The term -2*i because we first put 2 balls in every urn so that problem is now transformed into a standard one containing at least 1 balls, for each i.

    https://atcoder.jp/contests/abc178/submissions/16705277

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

For problem C: I'm thinking like this, place 0 and 9 in any two places (nC2) then other n-2 places will have 10 possibilities hence (10^(n-2)). So overall answer is nC2 *(10^(n-2)).

Can anyone say what fact am i assuming wrong/missing. Thanks :)

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

atdynamicprogrammer

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

lose again because of my speed

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

Was trying to do D , using DP but gave TLE... https://atcoder.jp/contests/abc178/submissions/16721075 Can someone pls help what is wrong

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

Editorial:

A
B
C
D
E
F

All codes:https://atcoder.jp/contests/abc178/submissions?f.User=Gary

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

    In $$$C$$$ constraints are smaller, so if someone has weak combinatorics(like me) then dp is more intuitive imo. here is my sol using dp:

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

    Hey, in problem D, I think you also need to add 1 to dp[i].

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

Is there a case to be handled for mod of negative numbers in C ?

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

And.. AtCoder becomes MathCoder.

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

c explanation ?

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

Maybe this is an off-topic.

I think Atcoder should show counts of solve for each problem in dashboard/tasklist(like CF). I know it is in the standings page, but viewing standings itself some number of times is well-disgusting.

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

I have tried to solve F using bipartite graph matching but it failed just in test 16 :)))

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

I found my solution for F is realy complex(Though it is right)!!

Can you share your idea for F?

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

Can someone check why I'm getting WA on C . here is my submission

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

Just 2 min short to get AC in problem F. Nice F anyway

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

A Combinatorics solution for D — Redistribution

Recall that, by the famous Stars and Bars Theorem, the number of non-negative integral solutions of

$$$ x_1 + x_2 + \dots + x_r = n $$$

is

$$$ {n + r - 1} \choose {r - 1} $$$

Let us denote this value as $$$stars(n, r)$$$. Clearly, the value is 0 if $$$n$$$ is negative.

Moreover, if we add a constraint that $$$x_i \geq t$$$, then, we can replace $$$x_i$$$ by $$$y_i$$$, where

$$$ x_i = y_i + t $$$

This transforms the problem to finding the non-negative integral solutions of

$$$ y_1 + y_2 + \dots + y_r = n - r \cdot t $$$

Clearly, the number of valid solutions is $$$stars(n - r \cdot t, \ r)$$$

So, for each $$$r$$$ from 1 to $$$n$$$, we sum up the values of $$$stars(n - 3 \cdot r, \ r)$$$.

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

DP Solution for Problem C — Ubiquity

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

A great contest.

Unfortunately,I nealy AK(AC 5 problems),but I'm in trouble with the sixth problem.

All of them are Math problems(.(xiao xue ao shu in Chinese)

And there's Chinese in English task:配点。

Hope the abc will be better!

:)

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

So I did a randomized solution for F. I try three ways:

  1. Reverse $$$B$$$.

  2. Random shuffle $$$B$$$ for $$$T$$$ times.

  3. Rotate $$$B$$$ randomly for $$$T$$$ times.

$$$T = 20$$$ is sufficient to get AC, and it runs in 61 ms. Of course, I have no proof (well not even an intuition) for this. :D

So, I'll be glad if someone can hack this solution or give some proof/intuition for it.

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

How to prove that on F, if a solution exists, one of the cyclic shifts of b is also a solution?

I wrote my solution based on it and it passed.

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

My Unofficial tutorial (A-F) for this contest.

And the Chinese version.

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

Just a thought: How to solve F if the elements are unsorted in both the arrays?

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

Can somebody please help me find the only test case that is failing for my solution of problem E?

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

What's wrong with my solution of D?

I used dp, $$$dp_{ij}$$$ means the sequence‘s length is $$$i$$$ and its sum is $$$j$$$.

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

Why do you have the problem whose solution is available in CPH? The most popular book on CP, talking about problem E.

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

Sry for a newbie question, how to we see the test cases at atcoder???

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

How to solve E??

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

Can someone plz tell me why my code for task C is failing for 5 test cases?

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

ll help(ll a,ll b){
    if(b==0)return 1;
    if(b==1)return a;
    ll ans = 1;
    if(b&1){
        ans = help(a,b-1)*a;
    }
    else {
        ans  = help(a,b/2);
        ans = ans * ans;
    }
    return ans%mod;
}

int main(){
    ll n;
    cin>>n;
    ll x = help(10,n);
    ll y = help(9,n);
    ll z = help(8,n);
    ll res = x-2*y+z;      // error in this line
    cout<<res;
    return 0;    
}

UPD : Error found The error is, it should be replaced with ll res = (x- 2*y + z + 2*mod ) % mod;

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

F can be solved by maintaining an invariant as follows:

Hint1
Hint2
Hint3

Thanks to Yousef_Salama for showing me this idea, you can check his submission.

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

I have written unofficial English editorial, you can find it at: editorial

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

For F, I am reversing B and then checking if B[i]=A[i]. If so at index=p, I am reversing the array from B[0] to B[p] and from B[p+1] to B[n-1]. This works as for the reversed B, all numbers left of B[p] will be >= B[p] and to right of B[p] will be <= B[p]. Whereas in A, all numbers left of A[p] will be <= A[p] and to right of A[p] will be >= A[p]. Theoretically it should work but I am getting wrong answer in 3 of the 60 test cases and I cant figure out why. Can anyone point out the fault in my algo? Submission: https://atcoder.jp/contests/abc178/submissions/16733148

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

Problem F is EXACTLY the same with Perm Matrix (just with smaller constraints).

I've seen this problem,so I got an unexpected high rank.

My atcoder account: sjcsjcsjc

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

Hi can someone please tell why my submission for problem C is working in atcoder c++ compiler but not in my local compiler.

I have tried recursive dp solution for this problem and it is working well . But in some large input example for n = 869121 it gives segmentation fault in local compiler as well as in online cpp compiler but works well upon submitting can some please tell why this happening ? Can this be due to memory limit or recursion depth ? please help