QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296522 | #6625. Binaria | whdywjd | 0 | 13ms | 17156kb | C++14 | 2.7kb | 2024-01-03 09:09:48 | 2024-01-03 09:09:48 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <set>
#define ll long long
#define _1 first
#define _2 second
#define _mp make_pair
#define _pb push_back
#define MAX_N 1000003
using namespace std;
ll read(){ll x = 0;char c = 0, v = 0;do{c = getchar();if(c == '-')v = 1;} while(c < '0' || c > '9');do{x = (x << 3) + (x << 1) + c - '0';c = getchar();} while(c >= '0' && c <= '9');return v ? -x : x;}
const ll P = 1000003;
ll fp(ll x, ll k)
{
ll ans = 1;
for( ; k; k >>= 1, x = x * x % P)
if(k & 1)
ans = ans * x % P;
return ans;
}
ll fac[MAX_N], inv[MAX_N];
ll C(int n, int m)
{
if(n < m || m < 0)
return 0;
//printf("%lld %lld %lld\n", fac[n], inv[n - m], inv[m]);
return fac[n] * inv[n - m] % P * inv[m] % P;
}
int n, k;
int a[MAX_N];
int sta[MAX_N];
void MAIN()
{
n = read();
k = read();
for(int i = 1; i <= n - k + 1; i++)
a[i] = read();
for(int i = 1; i <= n; i++)
sta[i] = i;
for(int i = k + 1; i <= n; i++)
{
if(abs(a[i - k] - a[i - k + 1]) >= 2)
{
printf("0\n");
return;
}
if(a[i - k] == a[i - k + 1])
sta[i] = sta[i - k];
else if(a[i - k] < a[i - k + 1])
{
if(sta[i - k] == -1)
{
printf("0\n");
return;
}
if(sta[i - k] > 0)
for(int j = i, flag = -1; j >= 1; j -= k, flag = -flag - 1)
sta[j] = flag;
sta[i] = -1;
}
else if(a[i - k] > a[i - k + 1])
{
if(!sta[i - k])
{
printf("0\n");
return;
}
if(sta[i - k] > 0)
for(int j = i, flag = 0; j >= 1; j -= k, flag = -flag - 1)
sta[j] = flag;
sta[i] = 0;
}
}
/*for(int i = 1; i <= n; i++)
printf("%d ", sta[i]);
printf("\n");*/
//printf("E\n");
int sum = a[1], cnt = 0;
for(int i = 1; i <= k; i++)
if(sta[i] > 0)
cnt++;
else if(sta[i] == -1)
sum--;
//printf("%d %d\n", cnt, sum);
printf("%lld\n", C(cnt, sum));
}
void CLEAR()
{
;
}
void EXP()
{
int n = MAX_N - 1;
fac[0] = inv[0] = 1;
for(int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % P;
inv[n] = fp(fac[n], P - 2);
for(int i = n - 1; i; i--)
inv[i] = inv[i + 1] * (i + 1) % P;
}
int main()
{
EXP();
int T = 1;
while(T--)
MAIN(), CLEAR();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 7ms
memory: 17156kb
input:
1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 7ms
memory: 17116kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 13ms
memory: 17156kb
input:
10 3 1 2 2 2 2 2 2 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: -3
Wrong Answer
time: 9ms
memory: 17108kb
input:
10 3 1 1 0 1 2 3 2 2
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'
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%