QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#304759#8009. Growing Sequencesucup-team088#AC ✓15ms12112kbC++176.7kb2024-01-14 02:20:302024-01-14 02:20:30

Judging History

你现在查看的是最新测评结果

  • [2024-01-14 02:20:30]
  • 评测
  • 测评结果:AC
  • 用时:15ms
  • 内存:12112kb
  • [2024-01-14 02:20:30]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
//ll mod = 1;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000007;
const int mod17 = 1000000007;
const ll INF = (ll)mod17 * mod17;
typedef pair<int, int>P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;

using ld = double;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}
template<typename T>
vector<T> vmerge(vector<T>& a, vector<T>& b) {
	vector<T> res;
	int ida = 0, idb = 0;
	while (ida < a.size() || idb < b.size()) {
		if (idb == b.size()) {
			res.push_back(a[ida]); ida++;
		}
		else if (ida == a.size()) {
			res.push_back(b[idb]); idb++;
		}
		else {
			if (a[ida] < b[idb]) {
				res.push_back(a[ida]); ida++;
			}
			else {
				res.push_back(b[idb]); idb++;
			}
		}
	}
	return res;
}
template<typename T>
void cinarray(vector<T>& v) {
	rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
	rep(i, v.size()) {
		if (i > 0)cout << " "; cout << v[i];
	}
	cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	//if (x == 0)return 0;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
//mod should be <2^31
struct modint {
	int n;
	modint() :n(0) { ; }
	modint(ll m) {
		if (m < 0 || mod <= m) {
			m %= mod; if (m < 0)m += mod;
		}
		n = m;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
bool operator<(modint a, modint b) { return a.n < b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= (int)mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += (int)mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

ll gcd(ll a, ll b) {
	a = abs(a); b = abs(b);
	if (a < b)swap(a, b);
	while (b) {
		ll r = a % b; a = b; b = r;
	}
	return a;
}
template<typename T>
void addv(vector<T>& v, int loc, T val) {
	if (loc >= v.size())v.resize(loc + 1, 0);
	v[loc] += val;
}
/*const int mn = 2000005;
bool isp[mn];
vector<int> ps;
void init() {
	fill(isp + 2, isp + mn, true);
	for (int i = 2; i < mn; i++) {
		if (!isp[i])continue;
		ps.push_back(i);
		for (int j = 2 * i; j < mn; j += i) {
			isp[j] = false;
		}
	}
}*/

//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
	auto res = st.lower_bound(val);
	if (res == st.begin())return st.end();
	res--; return res;
}

//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
	auto res = st.lower_bound(val);
	return res;
}
using mP = pair<modint, modint>;
mP operator+(mP a, mP b) {
	return { a.first + b.first,a.second + b.second };
}
mP operator+=(mP& a, mP b) {
	a = a + b; return a;
}
mP operator-(mP a, mP b) {
	return { a.first - b.first,a.second - b.second };
}
mP operator-=(mP& a, mP b) {
	a = a - b; return a;
}
LP operator+(LP a, LP b) {
	return { a.first + b.first,a.second + b.second };
}
LP operator+=(LP& a, LP b) {
	a = a + b; return a;
}
LP operator-(LP a, LP b) {
	return { a.first - b.first,a.second - b.second };
}
LP operator-=(LP& a, LP b) {
	a = a - b; return a;
}

mt19937 mt(time(0));

const string drul = "DRUL";
string senw = "SENW";
//DRUL,or SENW
//int dx[4] = { 1,0,-1,0 };
//int dy[4] = { 0,1,0,-1 };

//------------------------------------

modint calc(ll n, int x) {
	modint res = 1;
	rep(i, x)res *= n - i;
	res *= factinv[x];
	return res;
}
void solve() {
	int n; ll c; cin >> n >> c;
	ll v = (1ll) << (n - 1);
	c -= v;
	if (c < 0) {
		cout << 0 << "\n"; return;
	}
	vector<vector<modint>> dp;
	dp.resize(2);
	dp[0].push_back(1);
	rep(i, n - 1) {
		bool b = false;
		if (c & (1ll << i))b = true;
		int cl = i + 1;
		vector<vector<modint>> ndp(2);
		rep(j, 2)rep(k, dp[j].size()) {
			for (int ad = 0; ad <= cl; ad++) {
				int nk = (k + ad) / 2;
				int r = (k + ad) % 2;
				int nj = j;
				if (!b && r) {
					nj = 1;
				}
				if (b && !r) {
					nj = 0;
				}
				modint val = dp[j][k];
				val *= comb(cl, ad);
				addv(ndp[nj], nk, val);
			}
		}
		swap(dp, ndp);
	}
	ll d = c / (1ll << (n - 1));
	modint ans = 0;
	rep(j, 2)rep(k, dp[j].size()) {
		ll r = d - k - j;
		if (r < 0)continue;
		modint val = dp[j][k];
		val *= calc(r + n, n);
		ans += val;
	}
	cout << ans << "\n";
}



signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed<<setprecision(10);
	init_f();
	//init();
	//while(true)
	//expr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 10ms
memory: 11828kb

input:

1 5

output:

5

result:

ok answer is '5'

Test #2:

score: 0
Accepted
time: 9ms
memory: 11872kb

input:

3 6

output:

4

result:

ok answer is '4'

Test #3:

score: 0
Accepted
time: 6ms
memory: 11804kb

input:

15 179

output:

0

result:

ok answer is '0'

Test #4:

score: 0
Accepted
time: 10ms
memory: 11804kb

input:

35 1234567887654321

output:

576695683

result:

ok answer is '576695683'

Test #5:

score: 0
Accepted
time: 8ms
memory: 11844kb

input:

45 228228228

output:

0

result:

ok answer is '0'

Test #6:

score: 0
Accepted
time: 10ms
memory: 11840kb

input:

60 576460752303423487

output:

0

result:

ok answer is '0'

Test #7:

score: 0
Accepted
time: 14ms
memory: 11800kb

input:

60 576460752303423488

output:

1

result:

ok answer is '1'

Test #8:

score: 0
Accepted
time: 13ms
memory: 11880kb

input:

1 1000000000000000000

output:

716070898

result:

ok answer is '716070898'

Test #9:

score: 0
Accepted
time: 13ms
memory: 11900kb

input:

1 1

output:

1

result:

ok answer is '1'

Test #10:

score: 0
Accepted
time: 13ms
memory: 11840kb

input:

15 1

output:

0

result:

ok answer is '0'

Test #11:

score: 0
Accepted
time: 12ms
memory: 12112kb

input:

1 964573170374708959

output:

695628865

result:

ok answer is '695628865'

Test #12:

score: 0
Accepted
time: 13ms
memory: 12028kb

input:

2 336

output:

28224

result:

ok answer is '28224'

Test #13:

score: 0
Accepted
time: 9ms
memory: 12080kb

input:

5 463

output:

172916212

result:

ok answer is '172916212'

Test #14:

score: 0
Accepted
time: 13ms
memory: 11836kb

input:

7 75427

output:

523581579

result:

ok answer is '523581579'

Test #15:

score: 0
Accepted
time: 9ms
memory: 11804kb

input:

10 28166

output:

145818175

result:

ok answer is '145818175'

Test #16:

score: 0
Accepted
time: 9ms
memory: 11896kb

input:

12 77890

output:

724302124

result:

ok answer is '724302124'

Test #17:

score: 0
Accepted
time: 13ms
memory: 11880kb

input:

3 401245

output:

68076875

result:

ok answer is '68076875'

Test #18:

score: 0
Accepted
time: 6ms
memory: 12024kb

input:

8 511955

output:

109524351

result:

ok answer is '109524351'

Test #19:

score: 0
Accepted
time: 13ms
memory: 12080kb

input:

15 484969

output:

99426993

result:

ok answer is '99426993'

Test #20:

score: 0
Accepted
time: 9ms
memory: 11876kb

input:

30 779369

output:

0

result:

ok answer is '0'

Test #21:

score: 0
Accepted
time: 9ms
memory: 11764kb

input:

17 638679755

output:

132031375

result:

ok answer is '132031375'

Test #22:

score: 0
Accepted
time: 8ms
memory: 11880kb

input:

25 669522429

output:

896585516

result:

ok answer is '896585516'

Test #23:

score: 0
Accepted
time: 13ms
memory: 11864kb

input:

29 748278478

output:

563047844

result:

ok answer is '563047844'

Test #24:

score: 0
Accepted
time: 8ms
memory: 11868kb

input:

33 642978862039931

output:

550967529

result:

ok answer is '550967529'

Test #25:

score: 0
Accepted
time: 8ms
memory: 11840kb

input:

38 218051542638139

output:

29411033

result:

ok answer is '29411033'

Test #26:

score: 0
Accepted
time: 14ms
memory: 12084kb

input:

44 188775063557057

output:

185410072

result:

ok answer is '185410072'

Test #27:

score: 0
Accepted
time: 10ms
memory: 11900kb

input:

48 4677253159871213

output:

863467586

result:

ok answer is '863467586'

Test #28:

score: 0
Accepted
time: 8ms
memory: 11800kb

input:

22 854279883518523144

output:

916505804

result:

ok answer is '916505804'

Test #29:

score: 0
Accepted
time: 13ms
memory: 11880kb

input:

38 730620861826239715

output:

433138392

result:

ok answer is '433138392'

Test #30:

score: 0
Accepted
time: 14ms
memory: 12104kb

input:

54 435826341367976434

output:

237455633

result:

ok answer is '237455633'

Test #31:

score: 0
Accepted
time: 14ms
memory: 11904kb

input:

55 536518888651224157

output:

665085880

result:

ok answer is '665085880'

Test #32:

score: 0
Accepted
time: 7ms
memory: 12024kb

input:

56 413839394784728775

output:

647247529

result:

ok answer is '647247529'

Test #33:

score: 0
Accepted
time: 14ms
memory: 11876kb

input:

57 514531937773009201

output:

425329246

result:

ok answer is '425329246'

Test #34:

score: 0
Accepted
time: 11ms
memory: 11872kb

input:

58 391852448201481116

output:

522300883

result:

ok answer is '522300883'

Test #35:

score: 0
Accepted
time: 9ms
memory: 12024kb

input:

59 492544995484728838

output:

937899244

result:

ok answer is '937899244'

Test #36:

score: 0
Accepted
time: 14ms
memory: 11864kb

input:

60 693597573066212298

output:

490610488

result:

ok answer is '490610488'

Test #37:

score: 0
Accepted
time: 15ms
memory: 12092kb

input:

60 1000000000000000000

output:

13328531

result:

ok answer is '13328531'

Extra Test:

score: 0
Extra Test Passed