QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#743934#6794. Sequence to SequenceqwqwfAC ✓92ms13064kbC++141.5kb2024-11-13 20:21:452024-11-13 20:21:54

Judging History

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

  • [2024-11-13 20:21:54]
  • 评测
  • 测评结果:AC
  • 用时:92ms
  • 内存:13064kb
  • [2024-11-13 20:21:45]
  • 提交

answer

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize("Ofast","unroll-loops","inline")
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define pb push_back
#define pii pair<int,int>
#define MP make_pair
#define fi first
#define se second
using namespace std;
const int N=1e6+20,M=1e6+20,mod=998244353;
const int Inf=1e18;
int n,a[N],b[N],f[N][2][2];
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) cin>>b[i];
	for(int i=1;i<=n;i++) if(!a[i]&&b[i]) return cout<<-1<<'\n',void();
	for(int i=1;i<=n;i++) for(int j=0;j<2;j++) for(int k=0;k<2;k++) f[i][j][k]=-Inf;
	f[0][0][0]=0;
	for(int i=1;i<=n;i++){
		if(b[i]){
			int w1=(-a[i]+1),w2=(b[i]-a[i]);
			for(int j=0;j<2;j++) for(int k=0;k<2;k++) if(f[i-1][j][k]!=-Inf) for(int B=-1;B<2;B++) for(int A=0;A<=2;A++){
				int nj=max(0ll,j-A-B),nk=max(0ll,k+B);
				if(nj<2&&nk<2) f[i][nj][nk]=max(f[i][nj][nk],f[i-1][j][k]+A*w1+B*w2);
			}
		}
		else{
			int W=a[i];
			for(int j=0;j<2;j++) for(int k=0;k<2;k++) if(f[i-1][j][k]!=-Inf) for(int D=0;D<2;D++){
				int nj=max(0ll,j+D),nk=max(0ll,k);
				if(nj<2&&nk<2) f[i][nj][nk]=max(f[i][nj][nk],f[i-1][j][k]+D*W);
			}
		}
	}
	int ans=0;
	for(int j=0;j<2;j++) for(int k=0;k<2;k++) ans=max(ans,f[n][j][k]);
	cout<<ans<<'\n';
}
signed main(){
//	freopen("game.in","r",stdin);
//	freopen("game.out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int T;cin>>T;
	while(T--) solve();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7668kb

input:

2
5
1 1 1 1 1
2 0 2 0 2
7
3 1 2 3 2 1 4
2 0 0 0 0 0 2

output:

3
3

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 92ms
memory: 13064kb

input:

110121
5
0 0 0 0 0
1 4 5 4 1
5
1 0 0 0 0
0 6 8 6 1
5
2 0 0 0 0
4 4 1 3 6
5
3 0 0 0 0
5 1 1 7 6
5
4 0 0 0 0
6 8 7 0 8
5
5 0 0 0 0
5 9 7 7 5
5
6 0 0 0 0
9 2 2 8 0
5
7 0 0 0 0
9 4 7 0 9
5
8 0 0 0 0
6 7 3 7 5
5
9 0 0 0 0
4 0 9 1 4
5
0 1 0 0 0
0 6 6 3 0
5
1 1 0 0 0
3 4 3 4 9
5
2 1 0 0 0
0 4 0 1 4
5
3 1 0...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 110121 tokens

Extra Test:

score: 0
Extra Test Passed