Logo Wy Online Judge

WyOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#669#113. 【0621 模拟赛】ZrinkaJtwang11002130ms198984kbC++14890b2025-06-21 15:42:522025-06-21 23:51:47

answer

#include<iostream>
using namespace std;
int n,m;
int a[5005],b[5005];
int dp[5005][5005][2];//取到a[i],b[j]时的最小最大值,最后是0a  1b
const int inf=0x3f3f3f3f3f3f3f3f;
int next(int x,int jiou){
	if((x+1)%2==jiou)	return x+1;
	else	return x+2;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i];
	cin>>m;
	for(int i=1;i<=m;i++)	cin>>b[i];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i==0&&j==0)	continue;
			//取a[i]过来
			if(i>=1)	dp[i][j][0]=min(next(dp[i-1][j][0],a[i]),next(dp[i-1][j][1],a[i]));
			else	dp[i][j][0]=inf;
			//取b[j]过来
			if(j>=1)	dp[i][j][1]=min(next(dp[i][j-1][0],b[j]),next(dp[i][j-1][1],b[j]));
			else	dp[i][j][1]=inf;
		}
	}
	/*for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			cout<<dp[i][j][0]<<","<<dp[i][j][1]<<" ";
		}
		cout<<endl;
	}*/
	cout<<min(dp[n][m][0],dp[n][m][1]);
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 15
Accepted

Test #1:

score: 15
Accepted
time: 1ms
memory: 3396kb

input:

0
500 1 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 ...

output:

750

result:

ok "750"

Test #2:

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

input:

0
500 0 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 ...

output:

737

result:

ok "737"

Test #3:

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

input:

0
500 0 1 0 0 1 0 0 0 1 0 0 0 1 1 0 1 0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 1 1 ...

output:

756

result:

ok "756"

Test #4:

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

input:

0
500 1 1 0 0 1 1 1 1 0 1 0 0 0 0 1 0 0 1 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 1 0 ...

output:

745

result:

ok "745"

Test #5:

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

input:

0
500 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 1 1 1 ...

output:

738

result:

ok "738"

Test #6:

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

input:

0
500 1 1 0 1 0 1 0 1 0 0 1 1 1 1 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 1 0 1 ...

output:

753

result:

ok "753"

Subtask #2:

score: 20
Accepted

Test #7:

score: 20
Accepted
time: 3ms
memory: 22260kb

input:

500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

1490

result:

ok "1490"

Test #8:

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

input:

500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

1468

result:

ok "1468"

Test #9:

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

input:

500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

1516

result:

ok "1516"

Test #10:

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

input:

500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

1502

result:

ok "1502"

Test #11:

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

input:

500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

1484

result:

ok "1484"

Test #12:

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

input:

500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

1502

result:

ok "1502"

Subtask #3:

score: 20
Accepted

Test #13:

score: 20
Accepted
time: 1ms
memory: 22364kb

input:

500 1 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 0 ...

output:

1088

result:

ok "1088"

Test #14:

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

input:

500 0 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 0 ...

output:

1100

result:

ok "1100"

Test #15:

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

input:

500 0 1 0 0 1 0 0 0 1 0 0 0 1 1 0 1 0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 1 1 0 ...

output:

1089

result:

ok "1089"

Test #16:

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

input:

500 1 1 0 0 1 1 1 1 0 1 0 0 0 0 1 0 0 1 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 1 0 0 ...

output:

1099

result:

ok "1099"

Test #17:

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

input:

500 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 1 1 1 1 ...

output:

1085

result:

ok "1085"

Test #18:

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

input:

500 1 1 0 1 0 1 0 1 0 0 1 1 1 1 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 1 0 1 0 ...

output:

1087

result:

ok "1087"

Subtask #4:

score: 7
Accepted

Test #19:

score: 7
Accepted
time: 175ms
memory: 198940kb

input:

5000 1 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 1 1 0 1 0 1 1 1 1 0 1 0 0...

output:

10836

result:

ok "10836"

Test #20:

score: 0
Accepted
time: 176ms
memory: 198848kb

input:

5000 0 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 1 0 0 1 1 1 1 1 0 0 0 1 0 0...

output:

10782

result:

ok "10782"

Test #21:

score: 0
Accepted
time: 175ms
memory: 198984kb

input:

5000 0 1 0 0 1 0 0 0 1 0 0 0 1 1 0 1 0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 1 1 0...

output:

10795

result:

ok "10795"

Test #22:

score: 0
Accepted
time: 174ms
memory: 198764kb

input:

5000 1 1 0 0 1 1 1 1 0 1 0 0 0 0 1 0 0 1 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 1 0 0...

output:

10830

result:

ok "10830"

Test #23:

score: 0
Accepted
time: 177ms
memory: 198844kb

input:

5000 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 1 1 1 1...

output:

10809

result:

ok "10809"

Test #24:

score: 0
Accepted
time: 174ms
memory: 198880kb

input:

5000 1 1 0 1 0 1 0 1 0 0 1 1 1 1 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 1 0 1 0...

output:

10743

result:

ok "10743"

Test #25:

score: 0
Accepted
time: 176ms
memory: 198576kb

input:

5000 1 1 1 1 1 1 0 1 0 1 1 1 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 1 0 0 0 0 1 1 0 1 0 1 0 1 0 0 1 0 1...

output:

10801

result:

ok "10801"

Test #26:

score: 0
Accepted
time: 176ms
memory: 198836kb

input:

5000 0 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 1 1 1 0 1 0 0 1 0 1 1 1 1 0 0 1 1 1 1 1 1 0 0 0 1 1 1 0 1 0...

output:

10786

result:

ok "10786"

Test #27:

score: 0
Accepted
time: 175ms
memory: 198800kb

input:

5000 1 0 1 1 0 1 0 0 0 0 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 0 0 1 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 1 0 1...

output:

10778

result:

ok "10778"

Test #28:

score: 0
Accepted
time: 171ms
memory: 198764kb

input:

5000 1 0 0 1 0 1 1 1 1 1 1 1 0 1 0 1 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 1 1 0 0 1 1 1 1 0 1 0 1 1 1 1 0 0...

output:

10810

result:

ok "10810"

Test #29:

score: 0
Accepted
time: 176ms
memory: 198608kb

input:

5000 1 0 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1...

output:

10750

result:

ok "10750"

Test #30:

score: 0
Accepted
time: 176ms
memory: 198768kb

input:

5000 0 0 0 0 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 0 1 1 0 1 0 1 0 1 0 0 1 1 0 1 1 0...

output:

10804

result:

ok "10804"