Submission #9488071


Source Code Expand

Copy
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define Debug printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define debug(x) cerr<<#x<<'='<<x<<endl
#define mem(x,val) memset(x,val,sizeof x)
namespace mine
{
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
    template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
    bool IN(ll x,ll l,ll r){return l<=x and x<=r;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e3+10;

    ll fac[N],facinv[N];ll C(int n,int m){return (n<0 or n<m)?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
    int ct[N],pw[N][N];
    int f[N][N],g[N][N];
    void main()
	{
        fac[0]=1;fo(i,1,N-1) fac[i]=fac[i-1]*i%MOD;
        facinv[N-1]=invm(fac[N-1]);fd(i,N-1,1) facinv[i-1]=facinv[i]*i%MOD;
        int n=qread(),X=qread();fo(i,1,n) ct[qread()]++;g[0][0]=1;
        fo(i,0,X) fo(j,0,n) pw[i][j]=qpower(i,j);
        fd(now,X,1)
        {
            fo(cnt,0,(X+1)/2) fo(len,cnt*(now+1),X-(cnt-1)) if(g[cnt][len])
                fo(i,0,min((X-cnt+1-len)/now,(X+1)/2-cnt))
                // for(int i=0;cnt+i<=(X+1)/2 and len+i*now<=X-cnt+1;i++) 
                    add(f[cnt+i][len+i*now],1ll*g[cnt][len]*facinv[i]%MOD );  
            fo(cnt,0,(X+1)/2) fo(len,cnt*now,X-(cnt-1))
            {
                g[cnt][len]=1ll*f[cnt][len]*pw[len+cnt*(-now+1)][ct[now]]%MOD;
                f[cnt][len]=0;
            }
        }
        ll ans=0;fo(cnt,0,X) fo(len,0,X)
            add(ans, fac[cnt]*g[cnt][len]%MOD*C(X-len+2-1,cnt)%MOD*((X-len)&1?MOD-1:1)%MOD );write(ans);
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}

Submission Info

Submission Time
Task E - Span Covering
User Zory
Language C++14 (GCC 5.4.1)
Score 1100
Code Size 2875 Byte
Status
Exec Time 60 ms
Memory 9472 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01, sample_02
All 1100 / 1100 fact_01, fact_02, max2_01, max2_02, max2_03, max2_04, max2_05, max2_06, max2_07, max2_08, max2_09, max2_10, max_01, max_02, max_03, max_04, max_05, max_06, max_07, max_08, max_09, max_10, random_01, random_02, random_03, random_04, random_05, sample_01, sample_02, small_01, small_02, small_03, small_04, small_05, zero_01, zero_02
Case Name Status Exec Time Memory
fact_01 8 ms 8832 KB
fact_02 17 ms 9088 KB
max2_01 40 ms 9472 KB
max2_02 39 ms 9472 KB
max2_03 57 ms 9472 KB
max2_04 57 ms 9472 KB
max2_05 53 ms 9472 KB
max2_06 53 ms 9472 KB
max2_07 50 ms 9472 KB
max2_08 50 ms 9472 KB
max2_09 39 ms 9472 KB
max2_10 39 ms 9472 KB
max_01 10 ms 9472 KB
max_02 9 ms 9472 KB
max_03 59 ms 9472 KB
max_04 59 ms 9472 KB
max_05 50 ms 9472 KB
max_06 50 ms 9472 KB
max_07 43 ms 9472 KB
max_08 43 ms 9472 KB
max_09 39 ms 9472 KB
max_10 39 ms 9472 KB
random_01 2 ms 8576 KB
random_02 3 ms 8832 KB
random_03 3 ms 8832 KB
random_04 3 ms 8832 KB
random_05 2 ms 6528 KB
sample_01 2 ms 4352 KB
sample_02 9 ms 9344 KB
small_01 1 ms 4352 KB
small_02 1 ms 4352 KB
small_03 2 ms 4352 KB
small_04 1 ms 4480 KB
small_05 1 ms 4480 KB
zero_01 60 ms 9472 KB
zero_02 60 ms 9472 KB