Submission #70011365


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(a);i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

template<int MOD, int RT> struct mint {
	static const int mod = MOD;
	static constexpr mint rt() { return RT; } // primitive root for FFT
	int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int
	mint():v(0) {}
	mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
		if (v < 0) v += MOD; }
	bool operator==(const mint& o) const {
		return v == o.v; }
	friend bool operator!=(const mint& a, const mint& b) { 
		return !(a == b); }
	friend bool operator<(const mint& a, const mint& b) { 
		return a.v < b.v; }
   
	mint& operator+=(const mint& o) { 
		if ((v += o.v) >= MOD) v -= MOD; 
		return *this; }
	mint& operator-=(const mint& o) { 
		if ((v -= o.v) < 0) v += MOD; 
		return *this; }
	mint& operator*=(const mint& o) { 
		v = int((ll)v*o.v%MOD); return *this; }
	mint& operator/=(const mint& o) { return (*this) *= inv(o); }
	friend mint pow(mint a, ll p) {
		mint ans = 1; assert(p >= 0);
		for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans; }
	friend mint inv(const mint& a) { assert(a.v != 0); 
		return pow(a,MOD-2); }
		
	mint operator-() const { return mint(-v); }
	mint& operator++() { return *this += 1; }
	mint& operator--() { return *this -= 1; }
	friend mint operator+(mint a, const mint& b) { return a += b; }
	friend mint operator-(mint a, const mint& b) { return a -= b; }
	friend mint operator*(mint a, const mint& b) { return a *= b; }
	friend mint operator/(mint a, const mint& b) { return a /= b; }
};

const int MOD=998244353; 
using mi = mint<MOD,5>; // 5 is primitive root for both common mods

namespace simp {
	vector<mi> fac,ifac,invn;
	void check(int x) {
		assert(mod==MOD);
		if (fac.empty()) {
			fac={mi(1),mi(1)};
			ifac={mi(1),mi(1)};
			invn={mi(0),mi(1)};
		}
		while (SZ(fac)<=x) {
			int n=SZ(fac),m=SZ(fac)*2;
			fac.resize(m);
			ifac.resize(m);
			invn.resize(m);
			for (int i=n;i<m;i++) {
				fac[i]=fac[i-1]*mi(i);
				invn[i]=mi(MOD-MOD/i)*invn[MOD%i];
				ifac[i]=ifac[i-1]*invn[i];
			}
		}
	}
	mi gfac(int x) {
		assert(x>=0);
		check(x); return fac[x];
	}
	mi ginv(int x) {
		assert(x>0);
		check(x); return invn[x];
	}
	mi gifac(int x) {
		assert(x>=0);
		check(x); return ifac[x];
	}
	mi binom(int n,int m) {
		if (m < 0 || m > n) return mi(0);
		return gfac(n)*gifac(m)*gifac(n - m);
	}
	mi binombf(int n,int m) {
		if (m < 0 || m > n) return mi(0);
		if (m>n-m) m=n-m;
		mi p=1,q=1;
		for (int i=1;i<=m;i++) p=p*(n+1-i),q=q*i;
		return p/q;
	}
}

const int N=110;
int n,a[N];
ll x,s;
mi dp[N][N*N],pd[N][N*N];

int main() {
	scanf("%d%lld",&n,&x);
	rep(i,0,n) {
		scanf("%d",&a[i]);
		a[i]+=1;
		s+=a[i];
	}
	s-=x;
	vector<PII> vs;
	rep(i,1,n+1) {
		vs.pb(mp(i,1));
	}
	rep(i,0,n) {
		vs.pb(mp(a[i],2));
	}
	//printf("!! %lld\n",s);
	sort(all(vs));
	dp[0][0]=1;
	int c0=0,c1=0;
	rep(i,0,SZ(vs)) {
		rep(j,0,min(c0,c1)+1) rep(k,0,n*n+1) {
			pd[j][k]=dp[j][k],dp[j][k]=0; 
		}
		auto [p,c]=vs[i];
		rep(j,0,min(c0,c1)+1) rep(k,0,n*n+1) if (pd[j][k]!=0) {
			if (k+p<=n*n) dp[j][k+p]+=pd[j][k];
			dp[j+1][k]+=((c==1)?(c1-j):(c0-j))*pd[j][k];
		}
		if (c==1) c0++; else c1++;
	}
	mi ans=0;
	for (ll k=max<ll>(s,0);k<=n*n;k++) ans+=dp[n][k];
	printf("%d\n",(int)ans);
}

Submission Info

Submission Time
Task A - Affinity for Artifacts
User apiad
Language C++ 20 (gcc 12.2)
Score 800
Code Size 4025 Byte
Status AC
Exec Time 99 ms
Memory 14292 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:118:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  118 |         scanf("%d%lld",&n,&x);
      |         ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:120:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  120 |                 scanf("%d",&a[i]);
      |                 ~~~~~^~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 47
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt, small_01.txt, small_02.txt, small_03.txt, small_04.txt, small_05.txt, small_06.txt, small_07.txt, small_08.txt, small_09.txt, small_10.txt, small_11.txt, small_12.txt, small_13.txt, small_14.txt, small_15.txt, small_16.txt, small_17.txt, small_18.txt, small_19.txt, small_20.txt
Case Name Status Exec Time Memory
hand_01.txt AC 86 ms 14280 KiB
hand_02.txt AC 91 ms 14020 KiB
hand_03.txt AC 93 ms 14072 KiB
hand_04.txt AC 99 ms 14216 KiB
random_01.txt AC 96 ms 14224 KiB
random_02.txt AC 93 ms 14228 KiB
random_03.txt AC 89 ms 14092 KiB
random_04.txt AC 98 ms 14124 KiB
random_05.txt AC 90 ms 14088 KiB
random_06.txt AC 90 ms 14224 KiB
random_07.txt AC 90 ms 14016 KiB
random_08.txt AC 92 ms 14020 KiB
random_09.txt AC 90 ms 14228 KiB
random_10.txt AC 98 ms 14056 KiB
random_11.txt AC 53 ms 14140 KiB
random_12.txt AC 16 ms 14292 KiB
random_13.txt AC 6 ms 13976 KiB
random_14.txt AC 5 ms 14128 KiB
random_15.txt AC 42 ms 14228 KiB
random_16.txt AC 18 ms 14280 KiB
random_17.txt AC 7 ms 14224 KiB
random_18.txt AC 5 ms 14120 KiB
random_19.txt AC 60 ms 14072 KiB
random_20.txt AC 17 ms 14080 KiB
sample_01.txt AC 5 ms 14204 KiB
sample_02.txt AC 5 ms 14276 KiB
sample_03.txt AC 5 ms 14212 KiB
small_01.txt AC 5 ms 14020 KiB
small_02.txt AC 5 ms 14084 KiB
small_03.txt AC 5 ms 14088 KiB
small_04.txt AC 5 ms 14216 KiB
small_05.txt AC 5 ms 14268 KiB
small_06.txt AC 5 ms 13980 KiB
small_07.txt AC 5 ms 14124 KiB
small_08.txt AC 5 ms 14076 KiB
small_09.txt AC 5 ms 14104 KiB
small_10.txt AC 5 ms 14228 KiB
small_11.txt AC 5 ms 14016 KiB
small_12.txt AC 5 ms 14084 KiB
small_13.txt AC 5 ms 13976 KiB
small_14.txt AC 5 ms 14144 KiB
small_15.txt AC 5 ms 13976 KiB
small_16.txt AC 5 ms 14020 KiB
small_17.txt AC 5 ms 14220 KiB
small_18.txt AC 5 ms 14076 KiB
small_19.txt AC 5 ms 14232 KiB
small_20.txt AC 5 ms 14228 KiB