QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#31742#1191. Reordering the DocumentsWu_RenWA 3ms3852kbC++14998b2022-05-12 08:59:242022-05-12 08:59:26

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-12 08:59:26]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3852kb
  • [2022-05-12 08:59:24]
  • 提交

answer

#include <bits/stdc++.h>
const int mod=1e9+7;
using namespace std;
struct seg{
	int mn,mx,sz;
	seg operator +(seg b){
		if(!sz) return b;
		if(!b.sz) return *this;
		if(mx>b.mn) puts("0"),exit(0);
		return (seg){mn,b.mx,sz+b.sz};
	}
}a[10010];
int n,m,K,f[2][5010],p,o;
void qmo(int &x){
	x+=(x>>31)&mod;
}
int main(){
	scanf("%d%d",&n,&K);
	for(int i=1,mx=0,w;i<=n;i++){
		scanf("%d",&w);
		if(w>mx) mx=w,a[++m]={w,w,1},a[++m]={0,0,0};
		else a[m]=a[m]+(seg){w,w,1};
	}
	for(int i=1;i<=m;i+=2){
		while(i+2<=m&&a[i+3].sz&&a[i].mx>a[i+3].mn){
			a[i]=a[i]+a[i+2];
			a[i+1]=a[i+1]+a[i+3];
			for(int j=i+2;j<=m-2;j++) a[j]=a[j+2];
			m-=2;
		}
	}
	f[0][0]=1,p=0,o=1;
	for(int i=1;i<=m;i+=2,p^=1,o^=1){
		for(int j=0;j<=n;j++) f[o][j]=0;
		for(int j=0;j<=n;j++) if(f[p][j]){
			qmo(f[o][j+a[i].sz]+=f[p][j]-mod);
			qmo(f[o][j+a[i+1].sz]+=f[p][j]-mod);
		}
	}
	int ans=0;
	for(int i=0;i<=n;i++) if(i<=K&&n-i<=K) qmo(ans+=f[p][i]-mod);
	printf("%d\n",ans);
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 3784kb

input:

6 3
1 3 4 2 6 5

output:

4

result:

ok answer is '4'

Test #2:

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

input:

6 6
1 3 4 2 6 5

output:

8

result:

ok answer is '8'

Test #3:

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

input:

4 4
4 3 1 2

output:

0

result:

ok answer is '0'

Test #4:

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

input:

6 3
1 3 4 2 6 5

output:

4

result:

ok answer is '4'

Test #5:

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

input:

6 6
1 3 4 2 6 5

output:

8

result:

ok answer is '8'

Test #6:

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

input:

4 4
4 3 1 2

output:

0

result:

ok answer is '0'

Test #7:

score: -100
Wrong Answer
time: 3ms
memory: 3800kb

input:

1000 500
4 5 6 8 10 11 12 13 14 15 20 23 25 26 28 29 33 35 1 2 36 38 3 7 41 9 16 44 48 17 18 51 52 53 19 21 54 22 24 59 61 62 27 67 30 31 32 34 68 69 37 39 73 40 76 77 42 81 83 43 85 45 87 46 89 94 47 95 49 50 97 101 55 103 105 56 57 58 106 60 108 110 63 111 114 64 115 65 119 66 70 71 120 121 72 124...

output:

456993559

result:

wrong answer expected '11363968', found '456993559'