【atcoder】GP 2 [agc036C]

  Topic Portal: https://atcoder.jp/contests/agc036/tasks/agc036_c

  Topic effect: to give you a length $ N $ 0 initial sequence of the whole, each operation you can find two different elements, one increment 1, a 2 increment, asked after operations $ M $, how much can appear different sequences.

  When analyzing this question when the game leakage conditions, resulting in a final sample has been trouble, but considering the conditions on the missing analysis it is more complicated.

  If we can find a sequence $ a $ is legal if and only if it satisfies the following conditions:

    1. $\sum_{i=1}^{N} a_i=3M$。

    2. The entire sequence was at most $ M $ odd.

    3. $\max_{i=1}^{N} a_i<=2M$。

  Proven consider $ M $ mathematical induction.

  We can ignore the first three conditions, the odd number of enumeration $ I $, it is equivalent to a whole number of columns is an even number, together with a selection $ I $ 1, the total number of programs $ \ sum_ {i = 1} ^ {\ min (N, m)} \ binom {N} {i} \ binom {N-1 + 3M-i} {N-1} $, can be time complex $ O (n + m) $ degree under the calculation.

  Then consider the conditions are not satisfied minus the number of Scheme 3. Since the sequence is greater than $ 2M $ at most one element, so that we can handpicked greater than $ 2M $ elements as $ a_1 $, and subtracted $ 2M $, so the operation sequence and the original sequence if they meet the original sequences satisfying the condition 2, condition 3 is not satisfied, if and only if the sequence satisfies the following operating conditions:

    a. $\sum_{i=1}^{N} a_i=3M$。

    B. the entire sequence of at most $ M $ odd. (Minus $ 2M $ does not change the parity)

    c. $a_1>0$。

  We then these programs considered the subtraction of two parts: ignoring the condition c c program subtracts considered illegal answer, we found that this condition is ignored embodiment are similar to conditions c above conditions 1 and 2, a similar procedure can be used statistics, while considering conditions as Imperial c $ a_1 = 0 $, so a direct translation of the entire sequence, $ N $ 1 and then decremented to statistics.

  Code:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define mod 998244353
#define Mod1(x) (x>=mod?x-mod:x)
#define Mod2(x) (x<0?x+mod:x)
#define maxn 3000010
inline ll read()
{
    ll x=0; char c=getchar(),f=1;
    for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
    for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    return x*f;
}
inline void write(ll x)
{
    static int buf[20],len; len=0;
    if(x<0)x=-x,putchar('-');
    for(;x;x/=10)buf[len++]=x%10;
    if(!len)putchar('0');
    else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
ll fac[maxn],inv[maxn];
int n,m;
inline ll power(ll a,ll b)
{
    ll ans=1;
    for(;b;b>>=1,a=a*a%mod)
        if(b&1)ans=ans*a%mod;
    return ans;
}
inline ll C(int n,int m){return fac[n]*inv[m]%mod*inv[n-m]%mod;}
inline ll calc(int n,int m,int k)
{
    ll sum=0;
    for(int i=0;i<=n&&i<=k;i++)
        if(!((m-i)&1)&&m>=i)sum=(sum+C(n,i)*C((m-i)/2+n-1,n-1))%mod;
    // writeln(sum);
    return sum;
}
int main()
{
    n=read(); m=read();
    fac[0]=inv[0]=1;
    for(int i=1;i<=n+3*m;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=power(fac[i],mod-2);
    }
    ll ans=(calc(n,3*m,m)-n*(calc(n,m,m)-calc(n-1,m,m)+mod))%mod;
    writeln(Mod2(ans));
    return 0;
}
agc036C

 

Guess you like

Origin www.cnblogs.com/quzhizhou/p/11228893.html