QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694496#7075. Let's Play Jigsaw Puzzles!ucup-team4352#WA 1996ms357636kbC++231.8kb2024-10-31 18:05:062024-10-31 18:05:06

Judging History

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

  • [2024-10-31 18:05:06]
  • 评测
  • 测评结果:WA
  • 用时:1996ms
  • 内存:357636kb
  • [2024-10-31 18:05:06]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define lowbit(x) (x&-x)
#define log(x) (31^__builtin_clz(x))
using namespace std;
const int maxn=1e4+5;
int a[maxn];
vector<int>dp[maxn];
vector<int>ans[maxn];
vector<short>loc[maxn];
int n;
int now[maxn];
short find(int x,int y,int nx,int ny){
	short l=y+1,r=n+1;
	while(l<r){
		short mid=l+r-1>>1;
		if(ans[x+1][mid-(x+1)]+nx>ans[y+1][mid-(y+1)]+ny)l=mid+1;
		else r=mid;
	}
	return l;
}
void solve(){
	n=8e3;
	// cin>>n;
	for(int i=1;i<=n;i++){
		a[i]=i;
		// cin>>a[i];
		dp[i].resize(i+1);
	}
	for(int i=1;i<=n;i++){
		int mn=a[i],mx=a[i];
		for(int j=i;j<=n;j++){
			mx=max(mx,a[j]);
			mn=min(mn,a[j]);
			ans[i].push_back(mx-mn);
		}
	}
	dp[0]={0};
	
	for(int i=1;i<=n;i++){
		dp[i][1]=ans[1][i-1];
		dp[i][i]=0;
		loc[i]={(short)i};
		for(int j=2;j<i;j++){
			while(now[j-1]+1<loc[j-1].size()&&find(loc[j-1][now[j-1]],loc[j-1][now[j-1]+1],dp[loc[j-1][now[j-1]]][j-1],dp[loc[j-1][now[j-1]+1]][j-1])<=i)now[j-1]++;
			dp[i][j]=dp[loc[j-1][now[j-1]]][j-1]+ans[loc[j-1][now[j-1]]+1][i-(loc[j-1][now[j-1]]+1)];
			// cout<<loc[j-1][now[j-1]]<<" "<<loc[j-1].size()<<"\n";
		}
		// cout<<"\n";
		if(i<n)
		for(int j=1;j<i;j++){
			while(loc[j].size()>1){
				int tmp=loc[j].back(),tmp1=loc[j][loc[j].size()-2];
				int nw=find(tmp,i,dp[tmp][j],dp[i][j]);
				int lst=find(tmp,tmp1,dp[tmp][j],dp[tmp1][j]);
				// if(0){
				if(nw<=lst){
					loc[j].pop_back();
				}
				else{
					break;
				}
			}
			loc[j].push_back(i);
		}
		// for(int j=1;j<=i;j++)cout<<dp[i][j]<<" ";cout<<"\n\n";
	}
	for(int j=1;j<=n;j++)cout<<dp[n][j]<<"\n";
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)solve();
    return 0;
}
/*
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1996ms
memory: 357636kb

input:

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

output:

7999
7998
7997
7996
7995
7994
7993
7992
7991
7990
7989
7988
7987
7986
7985
7984
7983
7982
7981
7980
7979
7978
7977
7976
7975
7974
7973
7972
7971
7970
7969
7968
7967
7966
7965
7964
7963
7962
7961
7960
7959
7958
7957
7956
7955
7954
7953
7952
7951
7950
7949
7948
7947
7946
7945
7944
7943
7942
7941
7940
...

result:

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