QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#393982 | #6625. Binaria | RedreamMer | 0 | 8ms | 22712kb | C++23 | 2.1kb | 2024-04-19 19:55:30 | 2024-04-19 19:55:31 |
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);
}
if(f(a + 1) == f(a + 2)) return cout << 0, 0;
rep(i, 1, a) if(f(i) == i) {
assert(i >= a - b + 1);
}
int c = 0;
rep(i, a - b + 1, a) s[a - b + 1] -= f(i) == f(a + 2), c += f(i) == i;
// 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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 8ms
memory: 21948kb
input:
1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 7ms
memory: 22444kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: -3
Wrong Answer
time: 7ms
memory: 22712kb
input:
10 3 1 2 2 2 2 2 2 2
output:
3
result:
wrong answer 1st numbers differ - expected: '2', found: '3'
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%