QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#326839#6625. Binariatybbs#0 2ms11876kbC++141.1kb2024-02-14 08:54:192024-07-04 03:23:53

Judging History

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

  • [2024-07-04 03:23:53]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:11876kb
  • [2024-02-14 08:54:19]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e6+5,mod=1e6+3;
int c[N],a[N],fac[N];
struct DSU{
	int fa[N];
	void init(int n){
		for(int i=1;i<=n;i++){
			fa[i]=i;
		}
	}
	int find(int x){
		if(x==fa[x]) return x;
		return fa[x]=find(fa[x]);
	}
	void merge(int x,int y){
		int fx=find(x),fy=find(y);
		fa[fx]=fy;
	}
} dsu;
int qpow(int a,int n){
	if(n==0) return 1;
	int x=qpow(a,n/2);
	return (ll)x*x%mod*(n%2?a:1)%mod;
}
int inv(int x){
	return qpow(x,mod-2);
}
int main(){
	int n,k;cin>>n>>k;
	for(int i=1;i<=n-k+1;i++){
		cin>>c[i];
	}
	memset(a,-1,sizeof a);
	dsu.init(n);
	for(int i=2;i<=n-k+1;i++){
		if(c[i]==c[i-1]){
			dsu.merge(i-1,i+k-1);
		}
		if(c[i]>c[i-1]){
			a[i-1]=0,a[i+k-1]=1;
		}
		if(c[i]<c[i-1]){
			a[i-1]=1,a[i+k-1]=0;
		}
	}
	for(int i=1;i<=n;i++){
		a[dsu.find(i)]=a[i];
	}
	for(int i=1;i<=n;i++){
		a[i]=a[dsu.find(i)];
	}
	int tot=0,val=c[1];
	for(int i=1;i<=k;i++){
		if(a[i]==-1) tot++;
		if(a[i]==1) val--;
	}
	fac[0]=1;
	for(int i=1;i<=n;i++){
		fac[i]=(ll)fac[i-1]*i%mod;
	}
	cout<<(ll)fac[tot]*inv(fac[val])%mod*inv(fac[tot-val])%mod;
	
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 0ms
memory: 11820kb

input:

1 1
0

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

1 1
1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 11768kb

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: 0ms
memory: 11752kb

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: 0ms
memory: 11752kb

input:

10 3
2 2 2 2 2 2 2 2

output:

3

result:

ok 1 number(s): "3"

Test #6:

score: -3
Wrong Answer
time: 2ms
memory: 11832kb

input:

10 3
2 1 1 1 1 2 2 3

output:

2

result:

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

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%