QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212959 | #6346. Record Parity | happypotato | WA | 14ms | 21232kb | C++14 | 2.3kb | 2023-10-13 23:52:22 | 2023-10-13 23:52:23 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll int, ll int>
#define ff first
#define ss second
#define pb push_back
#pragma GCC optimize("O2")
using namespace std;
// debug template
#ifdef POTATO
#include "debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__)
#else
#define debug(...)
#endif
// convenient functions
inline void yes() { cout << "YES" << endl; return; }
inline void no() { cout << "NO" << endl; return; }
template <class T>
inline void out(T temp) { cout << temp << endl; return; }
// globals
#define int long long
const int MOD = 998244353;
int bigmod(int b, int p) {
b %= MOD;
int res = 1;
while (p) {
if (p & 1) res = (res * b) % MOD;
p >>= 1; b = (b * b) % MOD;
}
return res;
}
int modinv(int x) {
return bigmod(x, MOD - 2);
}
const int mxN = 1e6 + 1;
int fact[mxN], factinv[mxN];
int a[mxN];
int nCr(int n, int r) {
if (n < r) return 0;
int res = fact[n];
res = (res * factinv[r]) % MOD;
res = (res * factinv[n - r]) % MOD;
return res;
}
void init() {
// initialize
fact[0] = fact[1] = factinv[0] = factinv[1] = 1;
for (int i = 2; i < mxN; i++) {
fact[i] = (fact[i - 1] * i) % MOD;
}
factinv[mxN - 1] = modinv(fact[mxN - 1]);
for (int i = mxN - 2; i > 1; i--) {
factinv[i] = (factinv[i + 1] * (i + 1)) % MOD;
}
}
void solve(int &case_no) {
// solve
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
int ans = 0;
int cnt = 1;
for (int i = 2; i <= n; i++) {
if (a[i - 1] < a[i]) {
cnt++;
continue;
}
ans = (ans + nCr(cnt, k)) % MOD;
cnt = 1;
}
ans = (ans + nCr(cnt, k)) % MOD;
if (k & 1) ans = (MOD - ans) % MOD;
out(ans);
}
int32_t main() {
#ifdef POTATO
// assert(freopen("input.txt", "r", stdin));
// assert(freopen("output.txt", "w", stdout));
#endif
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
srand(time(NULL));
#ifdef POTATO
auto start = chrono::high_resolution_clock::now();
#endif
init();
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) solve(i);
#ifdef POTATO
auto end = chrono::high_resolution_clock::now();
cerr << "Execution time: "
<< chrono::duration_cast<chrono::milliseconds>(end - start).count()
<< " ms" << endl;
#endif
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 9ms
memory: 20540kb
input:
5 2 4 1 2 5 3
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 14ms
memory: 20228kb
input:
7 3 1 2 3 4 5 6 7
output:
998244318
result:
ok 1 number(s): "998244318"
Test #3:
score: 0
Accepted
time: 6ms
memory: 21232kb
input:
5 5 2 5 4 1 3
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: -100
Wrong Answer
time: 12ms
memory: 20176kb
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'