QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#393984 | #6625. Binaria | RedreamMer | 0 | 11ms | 23592kb | C++23 | 2.2kb | 2024-04-19 20:02:49 | 2024-04-19 20:02:50 |
Judging History
answer
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstdio>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
#define PB push_back
#define int long long
#define ll long long
#define vi vector<int>
#define siz(a) ((int) ((a).size()))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
void print(vi n) { rep(i, 0, siz(n) - 1) cerr << n[i] << " \n"[i == siz(n) - 1]; }
const int N = 1e6, mod = 1e6 + 3;
int a, b, s[N + 5], fa[N + 5];
int f(int n) {return fa[n] == n ? n : fa[n] = f(fa[n]);}
int fac[N + 5], inv[N + 5];
int qp(int n, int m = mod - 2) {
int res = 1;
for (; m; m >>= 1) {
if (m & 1) res = res * n % mod;
n = n * n % mod;
}
return res;
}
void init() {
fac[0] = fac[1] = 1;
rep(i, 2, N) fac[i] = fac[i - 1] * i % mod;
inv[N] = qp(fac[N]);
per(i, N - 1, 0) inv[i] = inv[i + 1] * (i + 1) % mod;
}
int C(int n, int m) {return fac[n] * inv[m] % mod * inv[n - m] % mod;}
signed main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
init();
cin >> a >> b;
rep(i, 1, a - b + 1) cin >> s[i];
rep(i, 1, a + 2) fa[i] = i;
rep(i, 1, a - b) {
if(abs(s[i] - s[i + 1]) > 1) return cout << 0, 0;
if(s[i] < s[i + 1]) {
fa[f(i)] = f(a + 1);
fa[f(i + b)] = f(a + 2);
}
else if(s[i] > s[i + 1]) {
fa[f(i)] = f(a + 2);
fa[f(i + b)] = f(a + 1);
}
else fa[f(i)] = f(i + b);
// rep(i, 1, a) cout << f(i) << " \n"[i == a];
}
// cout << f(1) << endl;
if(f(a + 1) == f(a + 2)) return cout << 0, 0;
rep(i, 1, a) if(f(i) == i) assert(i >= a - b + 1);
// cout << f(a + 2) << endl;
int c = 0;
rep(i, a - b + 1, a) s[a - b + 1] -= f(i) == f(a + 2), c += f(i) == i && f(i) != f(a + 1) && f(i) != f(a + 2);
// cout << s[a - b + 1] << ' ' << c << endl;
if(s[a - b + 1] < 0 || s[a - b + 1] > c) return cout << 0, 0;
cout << C(c, s[a - b + 1]);
return cerr << endl << 1.0 * clock() / CLOCKS_PER_SEC << endl, 0;
}
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 3
Accepted
time: 6ms
memory: 22312kb
input:
1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 4ms
memory: 22380kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 4ms
memory: 23008kb
input:
10 3 1 2 2 2 2 2 2 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 7ms
memory: 23592kb
input:
10 3 1 1 0 1 2 3 2 2
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 11ms
memory: 22900kb
input:
10 3 2 2 2 2 2 2 2 2
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: -3
Runtime Error
input:
10 3 2 1 1 1 1 2 2 3
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%