atcoder_official's blog

By atcoder_official, history, 4 weeks ago, In English

We will hold AtCoder Beginner Contest 473.

We are looking forward to your participation!

  • Vote: I like it
  • -40
  • Vote: I do not like it

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hoping to A,B,C,D at least.... :)

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I hope I could solve Task A-D.

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope it's not rubbish round like abc472.

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Another day for ABC

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

pls let me solve F?

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Maybe I can't solve B.

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hoping I can solve E

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope I can solve A,B,C,D.

Ans good luck to everyone!

»
4 weeks ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

D is a little bit difficult,I wonder what is the examiner thinking when he created this problem

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope I can solve E and F

»
4 weeks ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

wth with D problem..

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

The hell is the C problem i dont understand the language

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Was able to solve from A to E.

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

D was harder than E, i solved E in 0:25 minutes but couldnt solve D

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

bruhhh i should have focused on problem E instead of D... couldn't finish it :|

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Wuwuu.... (crying loudly)

My D TLEd....

Why is my program so slow QwQ...

If the evaluation machine is a supercomputer, it should be able to pass

My Code:

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

int n,k;

inline void write(int x){
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

void build(int pos, int val, deque<int> q){
	if(val==0){
		while(!q.empty()){
			write(q.front());
			putchar(' ');
			q.pop_front();
		}
		for(int i=pos; i<=n; i++) putchar('0'),putchar(' ');
		putchar('\n');
		return;
	}
	else if(pos>n||pos>val) return;
	for(int i=0; i*pos<=val; i++){
		q.push_back(i);
		build(pos+1,val-i*pos,q);
		q.pop_back();
	}
}
deque<int> q;
int main(){
	cin>>n>>k;
	build(1,k,q);
	return 0;
}
  • »
    »
    4 weeks ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    i thought D is just one of the basic backtracking problems?

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

      Basic backtracking problem? Can you tell me some resources where you practiced these problems? I seriously many-a-times get stuck at these problems thinking for an optimised solution when we only need to do brute force. This time also same thing happened.

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

        n = 10 and you'll probably know this is a backtracking problem. if your naive solution got a tle, you can think of how to do a low-level optimisation like somehow pruning early, like this problem, you dont backtracking the last element, and if the sum == k for print the rest of the array with 0. Most of the time you'll be find. That the constaint is small means one of those 2 things: - The problem is somehow easy and just need us to backtracking and pruning. - The problem is a np hard and need some heuristic or complex solution

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

          yeah I did see n=10 but I thought the depth of recursion will result in tle somehow....didn't practice much of these problems so just took leap of logic there...sigh...anyway thanks for responding.

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

      A mysterious backtracking problem with unclear meaning.

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

    try to deal pos == n in build(...)?

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

    you can try this ~~~~~ void backtrack(int pos, int sum, vector &cur) { if (sum == k) { for(int i = 1; i <= n; i++) { cout << (i < pos ? cur[i] : 0) << ' '; } return; } if (pos == n) { int rem = k — sum; if (rem % n == 0) { cur[n] = rem / n; for(int i = 1; i <= n; i++) { cout << cur[i] << ' '; } } return; }

    int mx = (k - sum) / pos;
    for(int val = 0; val <= mx; val++) {
        cur[pos] = val;
        backtrack(pos + 1, sum + pos * val, cur);
    }

    } ~~~~~ pruning early like this and you'll be fine

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

      hey, can you post your code in better format or give your submission link? i struggle a lot on backtracking.

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

          I did the same but why am I getting the TLE

          ~~~~~~~~~~~~~~~~ public class Main { public static List ans; public static int cnt = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long k = sc.nextLong(); ans = new ArrayList<>(); rec(1,n,k); }

          public static void rec(int i , int n , long k){
              // basecase
              if(i > n){
                  if(k == 0){
                      for(long a : ans){
                          System.out.print(a+" ");
                      }
                      System.out.println();
                  }
                  return;
              }
              // compute 
              for(long choice=0;choice<=k;choice++){
                  if((choice * i) > k) break;
                  ans.add(choice);
                  rec(i+1,n,k-(choice*i));
                  ans.remove(ans.size()-1);
              }
          }
          

          } ~~~~~~~~~~~~~~~~~~~

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

            it's not the same you know, in your code, you have a unnecessary state of computing the last element which +1 height to your dfs tree, and also you can pruning right after k == 0 (using the rest of the element as 0); (also limiting your choice when calculate for element i improve the time a lot); you can see those pruning in my code

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

    Wow, thanks everyone! I didn't expect so many replies! I was in class and couldn't reply in time. Sorry QwQ

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

A-F is quite easy, I think F is only *1800,only segment tree is used. But G probably needs NTT, it's a big difficulty gap.

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

upset,D is so difficult!!!

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I can tell that F is about a Fenwick tree,but I forgot the template.what a pity!

»
4 weeks ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

I AK ABC473.

A<B<C<E<F<G<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<D

D is not a problem!!!

E,F,G are BORING!!!

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I cannot figured out the combinatorics formula for the final problem. Guess my math skill isnt good enough. Can anyone show me the idea and walkthrough about how you figured out and solved it?

  • »
    »
    4 weeks ago, hide # ^ |
    Rev. 2  
    Vote: I like it +1 Vote: I do not like it

    Let f(n, k) be the answer. If you choose a card, it can be either the next you need or a wrong card.

    If it's the next you need (probability 1/n) you have 1/n * f(n-1, k-1) probability, because you need to play k-1 times and you have n-1 remaining cards that you don't know.

    If it's not the next card you need (probability (n-1)/n) You just discovered a card you will need in a future step, but this will also cost 1 more move to get that card, and there is still n-1 cards you don't know. So you spent 2 steps to reduce your problem to a n-1 problem. then probability will be (n-1)/n * f(n-1, k-2).

    After this I figure it out it was about Stirling numbers of the first kind because of the recurrence (ignoring the division by n) f(n,k) = f(n-1, k-1) + (n-1) * f(n-1, k-2) (The original recurrence is a little different, but you can find it changing some terms) and in the end I needed to divide the answer by n! (because in each step you divide by n and go to n-1).

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

    i dont know how to optimize my idea but i have some small solution about this problem. So firstly, i wen through the way to minimize the expected value for each permutation. The strategy is actually very simple, we go from left to right, flip the unrevealed cards, if the card is not what we looking for, we remember it, continue flipping. When x equal to a number that we have seen, turn back and eat it immediately. So the answer for a permutation is just simple, it's N + (number of time that we have to flips a card we dont eat); so we have dp[i][j] is the probability to have j steps to flip a card that we dont eat after considering the first i cards. it has 2 case for us to switch the state of the dp. the first is i is equal to x, which is the card we looking for, then the probability is 1 / i; if not the probability is i — 1 / i; so our dp formular should look like this: dp[i][j] = (1 / i) * (dp[i — 1][j]) + (i — 1 / j — 1) * dp[i — 1][j — 1]; I dont know how to optimize this further, maybe by using dnc and fft

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

Here is my solution for E. No idea what went wrong Link

No idea what case I am actually missing on

»
4 weeks ago, hide # |
Rev. 2  
Vote: I like it -8 Vote: I do not like it

I passed G... but at 21:40:22. :(

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Easy round

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I don't know why he likes eating cards:(

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I think that D is more difficult than other quetions!!! Since I've had so many TLEs... My Code:

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
const int N=3e5+5;
int n,a[20],k,len; 
int ans[N][20];
void solve();
void dfs(int x,int cnt){
	if(cnt>k) return ;
	if(x>n){
		if(cnt==k){
			len++;
			for(int i=1;i<=n;i++){
				ans[len][i]=a[i];
			}
		}
		return ;
	}
	if(cnt==k){
		dfs(n+1,cnt);
		return;
	}
	if(cnt<k&&cnt+x>k) return ;
	for(int i=0;i*x+cnt<=k;i++){
		a[x]=i;
		dfs(x+1,x*i+cnt);
		a[x]=0;
	}
} 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _=1;
//	cin>>_;
	while(_--){
		solve();
	}
	return 0;
}
void solve(){
	cin>>n>>k;
	dfs(1,0);
	for(int i=1;i<=len;i++){
		for(int j=1;j<=n;j++){
			cout<<ans[i][j]<<' ';
		}
		cout<<'\n';
	}
	return ;
}

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

    It's hard to come up with the idea of using DP to optimize pruning.

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

      I don't think dp is needed here...my solution passed without any dp whatsoever...or did I use dp without knowing?

      • »
        »
        »
        »
        4 weeks ago, hide # ^ |
         
        Vote: I like it -10 Vote: I do not like it

        I was forced to use DP pruning because the server was extremely slow during the contest.

        #include<bits/stdc++.h>
        using namespace std;
        #define int long long
        const int MAXK=200005;
        int n,k;
        bool dp[12][MAXK];
        int ans[12];
        void dfs(int p,int j){
            if(p>n){
                for(int i=1;i<=n;i++)cout<<ans[i]<<(i==n?'\n':' ');
                return;
            }
            for(int x=0;x<=j/p;x++){
                int nj=j-p*x;
                if(dp[p+1][nj]){
                    ans[p]=x;
                    dfs(p+1,nj);
                }
            }
        }
        signed main(){
            ios::sync_with_stdio(0);
            cin.tie(0);cout.tie(0);
            cin>>n>>k;
            dp[n+1][0]=1;
            for(int i=n;i>=1;i--){
                for(int j=0;j<=k;j++){
                    dp[i][j]=dp[i+1][j]||(j>=i&&dp[i][j-i]);
                }
            }
            dfs(1,k);
            return 0;
        }
        
        
  • »
    »
    4 weeks ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    I would also like to add my solution that I submitted after contest was over T_T ... During the contest I was so sure it wouldn't pass.

    code
»
4 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

D is VERY terrible.The others are not tooooooooooo bad.

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In the editorial for problem G — Wipeout, en_translator cleverly utilizes #include<atcoder/all> to implement the NTT function. I find this quite impressive. Would someone kindly explain how to correctly use the atcoder namespace?

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I solved D with DFS:)

But I spent too much time on D, so my pref is low, MY RANTING IS ABOUT MY SCORE GOING STRAIGHT INTO THE TOILET!!!

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

My code of D get AC*37 and TLE*1,why???Doesn't AtCoder Judge run fast?

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll cnt;
vector<vector<ll>> ans(300005,vector<ll>(15));
ll vec[15];
ll n,k;
void dfs(ll dep,ll rem){
	if(dep==0){
		if(rem==0){
			++cnt;
			for(ll i=1;i<=n;++i) ans[cnt][i]=vec[i];
		} 
		return;
	}
	if(rem<0) return;
	if(dep>rem){
		vec[dep]=0;
		dfs(dep-1,rem);
		return;
	}
	for(ll i=0;i<=rem/dep;++i){
		vec[dep]=i;
		dfs(dep-1,rem-i*dep);
		vec[dep]=0;
	}
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>k;
	dfs(n,k);
	sort(ans.begin()+1,ans.begin()+cnt+1);
	for(int i=1;i<=cnt;++i){
		for(int j=1;j<=n;++j){
			cout<<ans[i][j]<<" ";
		}
		cout<<"\n";
	}
	return 0;
}
»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why SO many NTT?

I ask this problem in LAST LAST week too.

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

In my opinion, A = B = C < E < F << D << G. What's so terrible about problem D is that you'd never figure out from pure thinking during the contest that a slightly optimized brute force could pass, and it takes way too much courage to actually write that kind of brute force in an ABC.

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why does the editorial for problem G use the atcoder namespace? I fucking wrote NTT by hand!I hate NTT.

»
4 weeks ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

BORING CONTEST! Why do u let me put so much time(nearly half an hour) on making my code run faster and faster on problem D? Why do u put NTT for problem G? Why is problem F almost a template for segment tree?

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

who can teach me how to solve G, please!!!

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This is my first time solving problem F.

»
4 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I got a TLE on D at least. :(

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

First F!!!

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Regret not having watched E

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

AtCoder is shamelessly promoting their ACL.The just put an NTT in problem G.

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This is my first pb , try to solve atleast 3 pb

»
3 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

this will be my first contest , try to solve atleast 3