atcoder_official's blog

By atcoder_official, history, 15 months ago, In English

We will hold AtCoder Beginner Contest 390.

We are looking forward to your participation!

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

| Write comment?
»
15 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I look forward to every weekend for atcoder contests

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

I am very weak in algorithms. What can I do?

At: https://atcoder.jp/users/da_ke

»
15 months ago, hide # |
 
Vote: I like it -24 Vote: I do not like it

Good luck!

»
15 months ago, hide # |
 
Vote: I like it +61 Vote: I do not like it

Downvoted.

The problem D is the shitest problem I have seen.

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

    Over 150 people passed only A,B,C,E,F but can't pass D.(including me)

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

    So, how is it done, did not solve it?

    E was simpler.

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

    What? I solved D by just doing brute force with recursion. I don't get how it has fewer solves than E tbh.

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

      How did you solve D, your approach?

      • »
        »
        »
        »
        15 months ago, hide # ^ |
        Rev. 4  
        Vote: I like it 0 Vote: I do not like it

        Here is the code of the recursive function. Basically, I just do it as: Try to add the current number (a[idx]) for each index of the vector sums (Basically making a copy of sums with the element increased), or just add it to the end of sums. When reaching the end, just take the xor and save it to a set.

        Code

        (Also as a side note, you can speed this up significantly by not using an unordered_set, but instead just use a vector, then use sort and unique on the vector to get the same result).

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

      My dfs got TLE.

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

    Agree! I used 1 hour to solve D and don't have time to solve F! (I can solve it in at most 40min)

    D is totally SHIT.

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

How to do D?

»
15 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

is E Binary Search + Dp??

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

Can anyone tell me what was wrong with my solution for Problem B, where the task was to determine whether the sequence is a progression or not? I tried to find all the ratios, store them in a map, and check if there were any other ratios by verifying the size of the map. Why did this solution fail in one test case? It would be very helpful if someone could explain the root cause of the failure

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    double pre, curr;
    map<double, int> ratio;
    cin >> pre;

    for (int i = 0; i < n - 1; i++)
    {
        cin >> curr;
        ratio[pre / curr]++;
        pre = curr;
    }
    ratio.size() == 1 ? cout << "Yes" : cout << "No";
}
»
15 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

Enough of coin-toss problems like D.

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

At least for me Problem D is related to Stirling numbers. I saw some ways to count partitions using stirling numbers, the next partition always need to have the first unused number in previous partitions. The total number of ways is the sum {n, 1}, {n, 2} ... {n, n}.

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

I work very slowly on question B, but most of the time I search for 'geometric progress' on Google. I think it should be briefly described in the question

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

Took a lot of time to solve ABC, solved E just after the contest ended :(

E was a good binary search + DP problem. How to solve D?

Good contest, thanks for the round math957963 sounansya and all testers!

»
15 months ago, hide # |
 
Vote: I like it +40 Vote: I do not like it

Problems on recursion always look for me like "do the exact implementation, as author did".

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

Can someone explain solution for F. Cannot understand the editorial

  • »
    »
    15 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it
    My solution
    • »
      »
      »
      15 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      how do you handle 2nd case here? Can you post your submission link pls?

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

        See below

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

          Got it, Thanks!

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

          If a[i]-1 and a[i]+1 exist and a[i] doesn't exist, then, p0!=-1 and p2!=-1 and p1==-1. Then, wrapping the line

          ans -= 1LL*max(0, min(p0,p2)-p1)*ep;
          

          in an if check, like this ..

          if(p0!=-1&&p2!=-1&&p1==-1){
              ans -= 1LL*max(0, min(p0,p2)-p1)*ep;
          }
          

          yields WA. Any idea why ?

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

I can't understand 3rd test case of problem D

Test Case — 3 :
6
71 74 45 34 31 60

Result :
84

How ? Explain anyone please!

  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it +23 Vote: I do not like it
    as you'r wish
»
15 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

In problem E, if each food contains all 3 vitamins and the input is like this: Ai1, Ai2, Ai3, Ci (where Aij is Aij units of jth vitamin) Then how do we solve the same problem?

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

Can someone explain approach for problem D? I didn't understand the editorial.

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

During the contest, I have a WONDERFUL solution for Problem D (I think the Problem E is harder than Problem D).

Seeing that $$$N$$$ is so small, it's not hard to think of a search implementation, so you can write a simple search: DFS to the $$$x$$$-th point, and then enumerate $$$i\in [1,N]$$$ to indicate that $$$A_x$$$ moved to $$$B_i$$$, when $$$x \gt N$$$ time to calculate the value of XOR, and use the unordered_map statistical answer can be. This has a time complexity of $$$O(N\times N^N)$$$, but in practice, because of the constant problem, only the testcases of $$$N\le 8$$$ can be passed in the time limit of $$$3\text{s}$$$.

Consider pruning (the official solution uses set, I don't know how to do QWQ), first of all, the enumeration range can be adjusted to $$$i\in [1,x]$$$, because the front moves to the back and the back moves to the front are the same, so the time complexity is reduced to $$$O(N\times N!)$$$, and can pass the testcases of $$$N\le 11$$$. Consider to continue optimization, found that when $$$B_j=0$$$ when the $$$A_i$$$ to $$$B_j$$$ operation is meaningless (just changed the position), so the transfer can be special judgment, so that can be used $$$1.5\text{s}$$$ perfect through this problem. The time complexity is $$$O(NB(N))$$$, where $$$B(N)$$$ denotes the Bell Number of $$$N$$$, and the maximum is $$$4213597$$$, which is sufficient to pass the question.

My Code.

#include <bits/stdc++.h>
#define ll long long
#define endl putchar(10)
#define spc putchar(32)
#define R register
using namespace std;
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x << " = " << x, endl
#endif

inline ll read()
{
    ll x=0,f=1; char c=getchar();

    while(c<48 || c>57)
    {
        if(c=='-') f=-1;
        c=getchar();
    }

    while(c>47 && c<58)
    x=(x<<1)+(x<<3)+c-48, c=getchar();
    return x*f;
}

inline void write(ll x)
{
    static ll sta[41]; ll top=0;
    if(x<0) putchar('-'), x=-x;
    do sta[top++]=x%10, x/=10; while(x);
    while(top) putchar(sta[--top]+48);
}

ll n,a[21],p[21],res,ans;
unordered_map<ll,ll> bz;

void dfs(ll x)
{
    if(x>n)
    {
        res=0;
        for(R int i=1; i<=n; ++i) res^=p[i];
        if(!bz[res]) bz[res]=1, ++ans; return;
    }

    for(R int i=1; i<=x; ++i)
    {
        if(!p[i]) continue;
        p[i]+=a[x]; p[x]-=a[x]; dfs(x+1);
        p[i]-=a[x]; p[x]+=a[x];
    }
}

int main()
{
    n=read();
    for(R int i=1; i<=n; ++i)
    a[i]=read(), p[i]=a[i];
    dfs(1); write(ans);
    return 0;
}
  • »
    »
    15 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    The time complexity isn't $$$O(N!)$$$ here; your solution is precisely the intended solution mentioned in the editorial.