QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203161#2481. PickpocketsBoulevardDust#WA 24ms20208kbC++202.0kb2023-10-06 15:53:352023-10-06 15:53:36

Judging History

This is the latest submission verdict.

  • [2023-10-06 15:53:36]
  • Judged
  • Verdict: WA
  • Time: 24ms
  • Memory: 20208kb
  • [2023-10-06 15:53:35]
  • Submitted

answer

#include<bits/stdc++.h>
#define N 100005
#define re 
#define ll long long
#define P 167772161
using namespace std;
int n,m,K,q,T;
inline void Rd(int &res){
	re char c;res=0;
	while(c=getchar(),c<48);
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>47);
}
int H,tot,u;
int w[N],a[N],Get[N],LOG[N];
int sumL[N],sumV[N];
int L[N],V[N];
void FWT(unsigned int *a,int n){
	for(int d=1;d<n;d<<=1)for(int m=d<<1,i=0;i<n;i+=m)for(int j=0;j<d;j++){
		int x=a[i+j],y=a[i+j+d];
		a[i+j+d]=x+y;
	}
}
void IFWT(unsigned int *a,int n){
	for(int d=1;d<n;d<<=1)for(int m=d<<1,i=0;i<n;i+=m)for(int j=0;j<d;j++){
		int x=a[i+j],y=a[i+j+d];
		a[i+j+d]=y-x;
	}
}
bool mk[25];
unsigned int f[17][70005],g[17][70005],h[17][70005];
int main(){
	Rd(H),Rd(n);u=1<<n;
	for(re int i=1;i<=H;i++){
		Rd(w[i]);
		if(w[i]>n){puts("0");return 0;}
	}
	for(re int k=1;k<=n;k++){
		int res=0;
		for(re int i=1;i<=n&&tot<=n;i++){
			if(w[i]>=k)res++;
			else if(res>0)a[++tot]=res,res=0;
		}
		if(res>0)a[++tot]=res,res=0;
		if(tot>n)break;
	}
	if(tot>n){puts("0");return 0;}
	for(re int i=1;i<=n;i++)Rd(L[i]),Rd(V[i]);
	for(re int i=1;i<u;i++)Get[i]=Get[i&(i-1)]+1;
	for(re int i=2;i<u;i++)LOG[i]=LOG[i>>1]+1;
	for(re int i=1;i<u;i++)sumL[i]=sumL[i&(i-1)]+L[LOG[i&-i]+1],sumV[i]=sumV[i&(i-1)]+V[LOG[i&-i]+1];
	
	bool flag=1;
	for(re int i=1;i<=tot;i++){
		for(re int s=0;s<u;s++)if(sumL[s]==a[i])g[Get[s]][s]=1,mk[Get[s]]=1;
		for(re int j=1;j<=n;j++)if(mk[j])FWT(g[j],u);
		
		if(flag){
			for(re int j=1;j<=n;j++){
				mk[j]=0;
				for(re int s=0;s<u;s++)f[j][s]=g[j][s],g[j][s]=0;
			}
			flag=0;
			continue;
		}
		
		for(re int j=1;j<=n;j++)
			for(re int k=1;k<=n;k++)if(mk[k]&&j+k<=n)
				for(re int s=0;s<u;s++)h[j+k][s]+=f[j][s]*g[k][s];
		
		for(re int j=1;j<=n;j++){
			mk[j]=0;
			for(re int s=0;s<u;s++)f[j][s]=h[j][s],h[j][s]=0,g[j][s]=0;
		}
	}
	for(re int i=1;i<=n;i++)IFWT(f[i],u);
	int res=0;
	for(re int i=1;i<=n;i++)
		for(re int s=0;s<u;s++)
			if(Get[s]==i&&f[i][s]!=0)res=max(res,sumV[s]);
	printf("%d\n",res);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11840kb

input:

2 2
1 2
1 5
2 5

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 1ms
memory: 9784kb

input:

2 2
1 2
2 5
1 5

output:

10

result:

ok single line: '10'

Test #3:

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

input:

3 4
2 1 2
3 2
1 1
1 2
1 3

output:

7

result:

ok single line: '7'

Test #4:

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

input:

1 5
2
1 2
1 5
1 3
1 5
1 3

output:

10

result:

ok single line: '10'

Test #5:

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

input:

1 5
1
1 2
1 1
1 2
1 5
1 2

output:

5

result:

ok single line: '5'

Test #6:

score: 0
Accepted
time: 1ms
memory: 5608kb

input:

1 7
0
1 5
1 5
1 5
1 2
1 5
1 3
1 6

output:

0

result:

ok single line: '0'

Test #7:

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

input:

3 6
2 1 1
2 1
3 5
2 3
3 3
2 4
3 3

output:

0

result:

ok single line: '0'

Test #8:

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

input:

2 5
1 1
1 5
2 4
1 4
2 2
1 1

output:

9

result:

ok single line: '9'

Test #9:

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

input:

1 2
1
1 5
1 4

output:

5

result:

ok single line: '5'

Test #10:

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

input:

2 4
0 1
1 6
2 2
2 5
2 5

output:

6

result:

ok single line: '6'

Test #11:

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

input:

3 5
0 0 0
3 2
3 1
3 1
1 3
1 5

output:

0

result:

ok single line: '0'

Test #12:

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

input:

3 6
0 1 0
3 3
1 3
1 2
1 2
1 3
3 2

output:

3

result:

ok single line: '3'

Test #13:

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

input:

2 7
2 0
2 2
1 6
2 4
1 6
1 6
1 2
2 6

output:

12

result:

ok single line: '12'

Test #14:

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

input:

2 6
0 3
2 3
2 16
1 12
2 10
1 16
1 8

output:

36

result:

ok single line: '36'

Test #15:

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

input:

3 13
4 0 3
1 19
3 12
1 13
2 19
1 18
3 4
3 10
1 13
1 19
2 10
3 15
1 20
3 5

output:

0

result:

ok single line: '0'

Test #16:

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

input:

4 2
3 2 4 0
4 10
3 14

output:

0

result:

ok single line: '0'

Test #17:

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

input:

4 6
3 1 3 1
4 9
4 18
1 15
3 15
2 6
1 19

output:

0

result:

ok single line: '0'

Test #18:

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

input:

3 14
3 0 1
3 16
3 7
3 9
3 11
3 15
3 15
2 16
1 1
2 18
3 16
3 13
3 11
1 4
3 4

output:

0

result:

ok single line: '0'

Test #19:

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

input:

2 9
3 1
1 18
1 15
1 15
1 4
2 17
1 4
2 1
1 15
2 16

output:

63

result:

ok single line: '63'

Test #20:

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

input:

1 9
2
1 5
1 11
1 20
1 10
1 10
1 11
1 9
1 8
1 19

output:

39

result:

ok single line: '39'

Test #21:

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

input:

4 7
1 0 0 2
4 15
4 18
2 8
2 2
2 6
3 11
3 11

output:

0

result:

ok single line: '0'

Test #22:

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

input:

2 2
2 3
2 6
1 1

output:

0

result:

ok single line: '0'

Test #23:

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

input:

1 15
4
1 2
1 12
1 7
1 5
1 13
1 10
1 7
1 5
1 1
1 18
1 9
1 5
1 17
1 9
1 6

output:

60

result:

ok single line: '60'

Test #24:

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

input:

4 14
4 4 0 4
4 20
2 13
2 4
1 20
3 4
4 6
3 9
2 8
1 19
3 14
2 18
2 18
1 15
1 19

output:

130

result:

ok single line: '130'

Test #25:

score: 0
Accepted
time: 1ms
memory: 7736kb

input:

2 5
0 0
1 16
2 20
1 16
2 3
2 11

output:

0

result:

ok single line: '0'

Test #26:

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

input:

2 8
4 0
2 7
1 20
2 10
2 17
1 17
1 17
1 15
2 20

output:

69

result:

ok single line: '69'

Test #27:

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

input:

4 12
4 1 2 1
1 17
3 18
4 19
1 7
4 19
3 19
1 6
1 18
2 3
3 17
1 9
3 4

output:

76

result:

ok single line: '76'

Test #28:

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

input:

1 14
2
1 13
1 15
1 17
1 9
1 1
1 15
1 9
1 18
1 13
1 4
1 20
1 11
1 18
1 18

output:

38

result:

ok single line: '38'

Test #29:

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

input:

4 8
4 0 4 3
4 16
4 13
1 6
1 12
4 10
3 19
4 16
3 6

output:

0

result:

ok single line: '0'

Test #30:

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

input:

2 6
0 3
2 8
2 2
2 13
2 15
1 19
1 9

output:

0

result:

ok single line: '0'

Test #31:

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

input:

5 13
3 1 4 1 0
2 5
3 1
5 12
5 9
4 13
5 1
2 6
3 6
2 8
2 15
4 5
1 8
3 12

output:

0

result:

ok single line: '0'

Test #32:

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

input:

4 9
3 2 4 3
4 14
4 10
4 11
1 14
4 8
3 17
4 12
3 9
3 9

output:

0

result:

ok single line: '0'

Test #33:

score: 0
Accepted
time: 5ms
memory: 13916kb

input:

2 15
1 0
2 4
2 17
2 4
2 4
1 7
2 10
1 9
1 8
2 20
1 1
2 9
1 6
1 17
2 15
2 4

output:

17

result:

ok single line: '17'

Test #34:

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

input:

100000 16
14443 55420 45271 59540 17506 45279 49513 7118 52062 23449 62240 81654 47001 82704 81577 90132 54258 108 41873 82899 73494 8454 43677 34844 92634 48581 7109 1530 89551 44235 82584 49481 69802 20448 78330 70257 67421 71672 45574 96521 64524 43129 33599 37095 57123 69486 6307 74558 9699 1494...

output:

0

result:

ok single line: '0'

Test #35:

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

input:

100000 16
34132 25992 9700 90156 37155 60117 91934 19647 21415 98451 85854 51164 39403 80732 68947 34179 10383 43258 89748 79195 49897 93439 99072 84649 3567 21423 59855 21175 31153 43214 81799 35873 50482 75563 11972 64395 85329 14962 60476 19670 77437 86503 26544 26505 97938 98378 18263 91959 1093...

output:

0

result:

ok single line: '0'

Test #36:

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

input:

100000 16
49337 49202 98923 88065 90751 42204 62277 46326 94035 61743 11491 18245 67892 65458 14981 83057 23342 60570 53140 91901 61983 77500 5364 30637 59391 20822 7992 68913 25963 56681 75276 54999 95145 6833 64626 37669 49186 62351 47235 26430 2217 29040 8409 79387 68362 31357 19385 15922 24388 2...

output:

0

result:

ok single line: '0'

Test #37:

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

input:

100000 16
100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 100000 0 10...

output:

0

result:

ok single line: '0'

Test #38:

score: 0
Accepted
time: 24ms
memory: 20208kb

input:

1 16
16
1 813962
1 261224
1 292357
1 26638
1 342500
1 220901
1 329926
1 283296
1 444155
1 512333
1 670909
1 546612
1 398289
1 243805
1 299229
1 241034

output:

5927170

result:

ok single line: '5927170'

Test #39:

score: 0
Accepted
time: 21ms
memory: 19856kb

input:

1 16
16
1 559357
1 192158
1 650434
1 120360
1 505929
1 98087
1 596733
1 565702
1 460486
1 797314
1 77027
1 569947
1 799522
1 791499
1 794206
1 658821

output:

8237582

result:

ok single line: '8237582'

Test #40:

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

input:

12 16
1 1 1 1 1 1 1 1 1 1 1 1
12 3
10 2
3 9
9 2
3 9
3 10
7 1
8 2
2 4
9 5
12 11
7 3
12 4
5 6
6 7
12 6

output:

26

result:

ok single line: '26'

Test #41:

score: 0
Accepted
time: 7ms
memory: 16328kb

input:

12 16
1 1 1 1 1 1 1 1 1 1 1 1
10 9
7 8
4 3
7 7
3 6
9 2
1 7
1 10
12 10
2 4
3 10
2 3
4 9
8 6
8 11
9 7

output:

42

result:

ok single line: '42'

Test #42:

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

input:

10 16
1 1 1 1 1 1 1 1 1 1
3 8
3 9
8 11
3 7
2 10
6 3
10 3
9 4
8 11
8 6
10 7
8 2
5 10
1 3
7 2
10 10

output:

29

result:

ok single line: '29'

Test #43:

score: -100
Wrong Answer
time: 6ms
memory: 16196kb

input:

18 16
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
9 9
1 4
4 3
6 6
16 3
13 6
2 3
7 5
8 4
12 4
12 6
11 3
11 3
16 1
5 4
10 2

output:

19

result:

wrong answer 1st lines differ - expected: '22', found: '19'