QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#956275#8147. Math ExamlyccAC ✓142ms82272kbC++202.8kb2025-03-29 18:26:172025-03-29 18:26:18

Judging History

This is the latest submission verdict.

  • [2025-03-29 18:26:18]
  • Judged
  • Verdict: AC
  • Time: 142ms
  • Memory: 82272kb
  • [2025-03-29 18:26:17]
  • Submitted

answer

// Author: lycc
// 
// Problem: # 8147. Math Exam
// Contest: 
// URL: https://qoj.ac/problem/8147
// Memory Limit: 1024 MB
// Time Limit: 1000 ms

#include <bits/stdc++.h>
// #define int long long
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define pb emplace_back
#define For(i, x, y) for (int i = (x); i <= (y); i++)
#define rep(i, x, y) for (int i = (x); i >= (y); i--)
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define sz(v) (int)((v).size())
#define ull unsigned long long
#define ls (p << 1)
#define rs (p << 1 | 1)
#define mp make_pair
#define i128 __int128
#define db long double
#define vi vector<int>
#define mem(v, x) memset(v, x, sizeof(v))
#define A3 array<int, 3>
#define A4 array<int, 4>
#define vpii vector<pair<int, int>>
using namespace std;
mt19937_64 rnd(time(0));
template< typename T > void cmin(T &x, T y) { return x = min(x, y), void(); }
template< typename T > void cmax(T &x, T y) { return x = max(x, y), void(); }
int ksm(int x, int y, int p) {
    int v = 1; x %= p;
    while (y) v = 1ll * v * ((y & 1) ? x : 1) % p, x = 1ll * x * x % p, y >>= 1;
    return (v % p + p) % p;
}
void file() {
	freopen("1.in", "r", stdin);
	freopen("1.out", "w", stdout);
	return;
}
bool MemoryST;
const int N = 1e7 + 5;
const int mod = 998244353;
const long long INF = 1e18;
const int base = 13131;
using ll = long long;
int fac[N], ifac[N];
int C(int x, int y) {
	if (x < 0 || y < 0 || x < y) return 0;
	return 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
#define add(x, y) ((x += y) >= mod ? (x -= mod) : 1)
int calc(int n, int m, int L, int R) {
	if (L <= 0 || R <= 0 || n + L <= m || n - R >= m) return 0;
	// (0, 0) -> (n, m)
	// y = x + L
	// y = x - R
	int ans = C(n + m, n);
	for (int i = n + L, j = 0; i <= n + m; (!j ? (i += R) : (i += L)), j ^= 1) {
		if (j) add(ans, C(n + m, i));
		else add(ans, mod - C(n + m, i));
	}
	for (int i = m + R, j = 0; i <= n + m; (!j ? (i += L) : (i += R)), j ^= 1) {
		if (j) add(ans, C(n + m, i));
		else add(ans, mod - C(n + m, i));
	}
	return ans;
}
int n, m;
void Main() {
	cin >> n >> m;
	fac[0] = ifac[0] = 1;
	For (i, 1, N - 1) fac[i] = 1ll * fac[i - 1] * i % mod;
	ifac[N - 1] = ksm(fac[N - 1], mod - 2, mod);
	rep (i, N - 2, 1) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod;
	int ans = 0;
	For (i, 0, n) {
		add(ans, calc(i, n - i, 1, (m + 1) / 2 + 1));
	}
	cout << ans;
    return;
}
bool MemoryED;
signed main() {
	// file();
    ios :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cerr << fixed << setprecision(6) << (&MemoryST - &MemoryED) / 1048576.0 << "MB\n";
    int TESTCNT = 1;
    // cin >> TESTCNT;
    while (TESTCNT --) Main();
    cerr << endl << 1e3 * clock() / CLOCKS_PER_SEC << "ms"; 
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 86ms
memory: 82184kb

input:

9 13

output:

124

result:

ok answer is '124'

Test #2:

score: 0
Accepted
time: 86ms
memory: 82200kb

input:

500 999

output:

195157058

result:

ok answer is '195157058'

Test #3:

score: 0
Accepted
time: 138ms
memory: 82124kb

input:

10000000 19260817

output:

475124613

result:

ok answer is '475124613'

Test #4:

score: 0
Accepted
time: 92ms
memory: 82084kb

input:

1234567 654321

output:

986926700

result:

ok answer is '986926700'

Test #5:

score: 0
Accepted
time: 93ms
memory: 82180kb

input:

1145141 11451

output:

186897097

result:

ok answer is '186897097'

Test #6:

score: 0
Accepted
time: 87ms
memory: 82096kb

input:

114514 11451

output:

91839230

result:

ok answer is '91839230'

Test #7:

score: 0
Accepted
time: 91ms
memory: 82084kb

input:

1145143 114555

output:

641840034

result:

ok answer is '641840034'

Test #8:

score: 0
Accepted
time: 95ms
memory: 82116kb

input:

2123181 1980523

output:

784155222

result:

ok answer is '784155222'

Test #9:

score: 0
Accepted
time: 107ms
memory: 82196kb

input:

4238693 1876847

output:

169222558

result:

ok answer is '169222558'

Test #10:

score: 0
Accepted
time: 129ms
memory: 82232kb

input:

7804655 10519823

output:

935955279

result:

ok answer is '935955279'

Test #11:

score: 0
Accepted
time: 134ms
memory: 82120kb

input:

9189568 17055313

output:

811181659

result:

ok answer is '811181659'

Test #12:

score: 0
Accepted
time: 88ms
memory: 82184kb

input:

683534 1001003

output:

569208897

result:

ok answer is '569208897'

Test #13:

score: 0
Accepted
time: 96ms
memory: 82160kb

input:

1850342 3700683

output:

852266054

result:

ok answer is '852266054'

Test #14:

score: 0
Accepted
time: 142ms
memory: 82272kb

input:

10000000 1234567

output:

387622638

result:

ok answer is '387622638'

Test #15:

score: 0
Accepted
time: 84ms
memory: 82124kb

input:

1 1

output:

1

result:

ok answer is '1'

Test #16:

score: 0
Accepted
time: 85ms
memory: 82172kb

input:

3 1

output:

1

result:

ok answer is '1'

Test #17:

score: 0
Accepted
time: 130ms
memory: 82116kb

input:

10000000 1

output:

1

result:

ok answer is '1'

Extra Test:

score: 0
Extra Test Passed