QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#103618#6346. Record Paritywnmrmr#WA 2ms3428kbC++231.8kb2023-05-07 04:44:052023-05-07 04:44:06

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-07 04:44:06]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3428kb
  • [2023-05-07 04:44:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
#define all(v) v.begin(), v.end()
#define pb push_back

void dbg_out() { cerr << endl; }
template<typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }

template<int MOD> 
struct mint {
	int x;

	mint(): x(0) {}
	mint(int y): x(y<0?y%MOD+MOD : y%MOD) {}
	
	void operator+=(mint rhs) { x += rhs.x; if(x>=MOD) x-= MOD; }
	void operator-=(mint rhs) { x -= rhs.x; if(x<0) x+= MOD; }
	void operator*=(mint rhs) { x *= rhs.x; x %= MOD; }
	void operator/=(mint rhs) { *this *= rhs.inv(); }
	mint operator+(mint rhs) { mint res = *this; res += rhs; return res; }
	mint operator-(mint rhs) { mint res = *this; res -= rhs; return res; }
	mint operator*(mint rhs) { mint res = *this; res *= rhs; return res; }
	mint operator/(mint rhs) { mint res = *this; res /= rhs; return res; }

	mint inv() { assert(x != 0); return this->pow(MOD-2); }
	mint pow(int e) {
		mint res = 1;
		for(mint p=*this;e>0;e/=2,p*=p) if(e%2)
			res *= p;
		return res;
	}
};
using Z = mint<998244353>;

void solve() {
	int n, k; cin >> n >> k;
	vector<int> a (n);
	for (auto &u : a) cin >> u;

	vector<Z> fat (n + 1);
	fat[0] = 1;
	for (int i = 1; i <= n; i++) fat[i] = fat[i - 1] * i;
	auto comb = [&] (int x, int y) {
		if (y > x) return Z(0);
		return fat[x] / fat[y] / fat[x - y];
	};

	Z ans = 0;
	int cur = 1;
	for (int i = 1; i < n; i++) {
		if (a[i] < a[i - 1]) {
			ans += comb (cur, k);
			cur = 1;
		}
		else cur++;
	}
	ans += comb (cur, k);

	cout << (ans * (k & 1 ? -1 : 1)).x << "\n";
}

signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3428kb

input:

5 2
4 1 2 5 3

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3352kb

input:

7 3
1 2 3 4 5 6 7

output:

998244318

result:

ok 1 number(s): "998244318"

Test #3:

score: 0
Accepted
time: 2ms
memory: 3424kb

input:

5 5
2 5 4 1 3

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 3420kb

input:

10 3
9 7 3 6 10 4 8 2 5 1

output:

998244352

result:

wrong answer 1st numbers differ - expected: '0', found: '998244352'