F - Valid payments Editorial by Huah


Let \(b_i=a_{i+1}-a_i(i<n)\),\(b_n=\inf\).

Firstly, a number \(X\) can be uniquely represented by a set as \(X=a_1*k_1+a_2*k_2+...+a_n*k_n(k_i< b_i)\)

Secondly, we need find the number of \(Y\) so that \(Y-Z=X\) and \(Y\& Z=0\)(Here we consider \(k_i>0\) as \(1\) and \(k_i=0\) as \(0\)). In fact, if \(Y\) is determined, then \(Z\) can be uniquely determined.

Therefore, this problem can be restated as follows:

Given \(X=a_1*k_1+a_2*k_2+...+a_n*k_n(k_i<b_i)\), find the number of \(Z\) so that \((Z+X)\& Z=0\).

Let \(Z=a_1*s_1+a_2*s_2+...+a_n*s_n\) and \(Y=a_1*p_1+a_2*p_2+...+a_n*p_n\), we can find that the following conditions should be met:

if \(k_i>0\) and \(s_i>0\) then \(s_i\) must be \(b_i-k_i\)(So that \(p_i=0,s_i>0\)).

if \(k_i=0\) then \(s_i=0\)(Becuase if \(k_i=0,s_i>0\) then \(p_i>0\)).

Meanwhile, because \(b_n=\inf\), then \(s_n\) always is \(0\).

Let \(f_{i,0/1}\) be the number of ways so that \(s_i=0/s_i>0\). the answer is \(f_{n-1,0}+f_{n-1,1}\). We can find the answer in \(O(n)\) time. https://atcoder.jp/contests/abc182/submissions/19459411

posted:
last update: